OOP for Dummies:
[Link] Console
Applications
Programming Part 7B
Chibi Tinodaishe – 0781081816(WhatsApp)
(Simple Notes for Zimsec Computer Science – Module Programming Part 7B)
Chapter 1: What Is Object-Oriented Programming (OOP)?
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.
The 4 Key Principles:
1. Encapsulation: Grouping data (attributes) and methods (functions) in a single unit
(class).
2. Inheritance: Creating new classes that reuse, extend, or modify the behavior of
existing classes.
3. Polymorphism: Allowing methods to do different things based on the object calling
them (method overriding).
4. Abstraction: Hiding complex details and showing only the necessary features of an
object.
Chapter 2: Getting Started with [Link] Console Applications
What is [Link]?
[Link] is a programming language by Microsoft that is easy to learn. Console applications
are programs that run in a command-line window.
Creating a Console App:
• Open Visual Studio.
• Select “Console App (.NET Framework)” in [Link].
• Write your code in the provided editor.
• Press F5 to run your application.
Chapter 3: Classes and Objects
Class: A blueprint that defines properties and methods.
Object: An instance of a class.
Example – Creating a Simple “Person” Class:
Module Module1
Sub Main()
' Create a new Person object
Dim person1 As New Person("John", 25)
[Link]()
[Link]() ' Pause to view output
End Sub
End Module
Public Class Person
' Private variables (Encapsulation)
Private _name As String
Private _age As Integer
' Constructor: used to create objects
Public Sub New(ByVal name As String, ByVal age As Integer)
_name = name
_age = age
End Sub
' A method to display information about the person
Public Sub DisplayInfo()
[Link]("Name: " & _name)
[Link]("Age: " & _age)
End Sub
End Class
Key Points:
• The constructor (Sub New) sets up the object when it’s created.
• DisplayInfo() shows the object's data.
Chapter 4: Encapsulation
What Is It?
Encapsulation keeps the data safe inside a class and only allows access via methods
(getters and setters).
Example – Using Properties in [Link]:
Public Class Student
' Private variables
Private _studentName As String
Private _marks As Integer
' Property for _studentName
Public Property StudentName() As String
Get
Return _studentName
End Get
Set(ByVal value As String)
_studentName = value
End Set
End Property
' Property for _marks
Public Property Marks() As Integer
Get
Return _marks
End Get
Set(ByVal value As Integer)
If value >= 0 And value <= 100 Then
_marks = value
Else
[Link]("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.
Example – Animal and Dog Classes:
' Base Class
Public Class Animal
Public Overridable Sub Speak()
[Link]("The animal makes a sound.")
End Sub
End Class
' Derived Class inherits from Animal
Public Class Dog
Inherits Animal
' Override the Speak method
Public Overrides Sub Speak()
[Link]("The dog barks.")
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.
Example – Continuing from the Animal/Dog Example:
Module Module1
Sub Main()
Dim myAnimal As Animal = New Animal()
Dim myDog As Animal = New Dog() ' Notice: declared as Animal type
[Link]() ' Outputs: The animal makes a sound.
[Link]() ' Outputs: The dog barks.
[Link]()
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 ([Link] uses “MustInherit” for abstract classes).
Example – Abstract Class for Shapes:
Public MustInherit Class Shape
Public MustOverride Function Area() As Double
End Class
Public Class Circle
Inherits Shape
Private _radius As Double
Public Sub New(ByVal radius As Double)
_radius = radius
End Sub
Public Overrides Function Area() As Double
Return [Link] * _radius * _radius
End Function
End Class
Public Class Rectangle
Inherits Shape
Private _width, _height As Double
Public Sub New(ByVal width As Double, ByVal height As Double)
_width = width
_height = height
End Sub
Public Overrides Function Area() As Double
Return _width * _height
End Function
End Class
Remember:
Abstract classes help you define a common interface for related classes while hiding the
underlying details.
Chapter 8: Putting It All Together – A Simple Console Application
Example – A Simple School App (Mini-Project):
Module Module1
Sub Main()
' Create a Student object and display info
Dim student1 As New Student
[Link] = "Alice"
[Link] = 85
[Link]("Student Name: " & [Link])
[Link]("Student Marks: " & [Link])
' Demonstrate inheritance and polymorphism
Dim animal1 As Animal = New Animal()
Dim animal2 As Animal = New Dog()
[Link]() ' Calls Animal's Speak
[Link]() ' Calls Dog's Speak
[Link]()
End Sub
End Module
Public Class Student
Private _studentName As String
Private _marks As Integer
Public Property StudentName() As String
Get
Return _studentName
End Get
Set(ByVal value As String)
_studentName = value
End Set
End Property
Public Property Marks() As Integer
Get
Return _marks
End Get
Set(ByVal value As Integer)
If value >= 0 And value <= 100 Then
_marks = value
Else
[Link]("Invalid marks!")
End If
End Set
End Property
End Class
Public Class Animal
Public Overridable Sub Speak()
[Link]("The animal makes a sound.")
End Sub
End Class
Public Class Dog
Inherits Animal
Public Overrides Sub Speak()
[Link]("The dog barks.")
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.
• Know the Syntax:
Be comfortable with [Link] syntax for defining classes, properties, methods, and
constructors.
• Review Past Questions:
Look at exam questions related to OOP and try to code the solutions.
• Keep It Simple:
In exams, clarity matters. Use clear naming for classes and methods.
Chapter 10: Conclusion and Further Reading
Congratulations! You now have a concise set of notes on OOP using [Link] for console
applications. Remember, practice is key. Experiment with these examples and try building
your own small projects. For further reading, check out:
• Microsoft’s official [Link] documentation.
• Online tutorials and forums like Stack Overflow.
These notes are designed to get you exam-ready. Stay focused, code often, and you’ll ace
those Zimsec Computer Science questions!