programming part 7b
programming part 7b
VB.NET Console
Applications
Programming Part 7B
Chibi Tinodaishe – 0781081816(WhatsApp)
(Simple Notes for Zimsec Computer Science – Module Programming Part 7B)
Definition:
OOP is a programming style based on the concept of “objects” that have properties (data)
and methods (actions). It makes it easier to structure and manage code by mimicking real-
life things.
2. Inheritance: Creating new classes that reuse, extend, or modify the behavior of
existing classes.
4. Abstraction: Hiding complex details and showing only the necessary features of an
object.
What is VB.NET?
VB.NET is a programming language by Microsoft that is easy to learn. Console applications
are programs that run in a command-line window.
Module Module1
Sub Main()
person1.DisplayInfo()
End Sub
End Module
_name = name
_age = age
End Sub
End Sub
End Class
Key Points:
• The constructor (Sub New) sets up the object when it’s created.
Chapter 4: Encapsulation
What Is It?
Encapsulation keeps the data safe inside a class and only allows access via methods
(getters and setters).
Get
Return _studentName
End Get
_studentName = value
End Set
End Property
' Property for _marks
Get
Return _marks
End Get
_marks = value
Else
Console.WriteLine("Invalid marks!")
End If
End Set
End Property
End Class
Tip: Use properties to protect your data and control how it is accessed.
Chapter 5: Inheritance
What Is It?
Inheritance allows a class to inherit attributes and methods from another class.
End Sub
End Class
' Derived Class inherits from Animal
Inherits Animal
End Sub
End Class
Usage:
When you call the Speak method on a Dog object, it uses the overridden version.
Chapter 6: Polymorphism
What Is It?
Polymorphism means “many forms” – the same method can behave differently on different
classes.
Module Module1
Sub Main()
Dim myDog As Animal = New Dog() ' Notice: declared as Animal type
Console.ReadLine()
End Sub
End Module
Key Idea:
Even though both objects are of type Animal, the Dog class’s Speak method is called for
myDog.
Chapter 7: Abstraction
What Is It?
Abstraction hides complex details and shows only the essential features.
How?
• Use abstract classes or interfaces (VB.NET uses “MustInherit” for abstract classes).
End Class
Inherits Shape
_radius = radius
End Sub
End Function
End Class
Public Class Rectangle
Inherits Shape
_width = width
_height = height
End Sub
End Function
End Class
Remember:
Abstract classes help you define a common interface for related classes while hiding the
underlying details.
Module Module1
Sub Main()
student1.StudentName = "Alice"
student1.Marks = 85
Console.ReadLine()
End Sub
End Module
Get
Return _studentName
End Get
_studentName = value
End Set
End Property
Get
Return _marks
End Get
_marks = value
Else
Console.WriteLine("Invalid marks!")
End If
End Set
End Property
End Class
End Sub
End Class
Inherits Animal
End Sub
End Class
Note: This mini-project shows a bit of everything: creating objects, using properties, and
demonstrating inheritance/polymorphism.
Chapter 9: Exam Tips for Zimsec Computer Science
• Understand Concepts:
Make sure you know the four pillars (Encapsulation, Inheritance, Polymorphism,
Abstraction).
• Practice Code:
Write and run small programs—modify examples to see different outcomes.
• Keep It Simple:
In exams, clarity matters. Use clear naming for classes and methods.
Congratulations! You now have a concise set of notes on OOP using VB.NET for console
applications. Remember, practice is key. Experiment with these examples and try building
your own small projects. For further reading, check out:
These notes are designed to get you exam-ready. Stay focused, code often, and you’ll ace
those Zimsec Computer Science questions!