0% found this document useful (0 votes)
18 views5 pages

Adv App Prog Assign

The document describes two systems implemented in VB.NET to demonstrate object-oriented programming concepts. The first system shows inheritance and polymorphism through an animal hierarchy with base Animal class and derived Dog and Snake classes. The second system demonstrates objects and classes through an employee management system with base Employee class and derived Manager class. Both systems showcase overriding methods to provide class-specific behavior.

Uploaded by

Mr Tuchel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views5 pages

Adv App Prog Assign

The document describes two systems implemented in VB.NET to demonstrate object-oriented programming concepts. The first system shows inheritance and polymorphism through an animal hierarchy with base Animal class and derived Dog and Snake classes. The second system demonstrates objects and classes through an employee management system with base Employee class and derived Manager class. Both systems showcase overriding methods to provide class-specific behavior.

Uploaded by

Mr Tuchel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

NAME: ALFRED ADEDE

REG: 19/02741

COURSE: BSD

UNIT: ADVANCED APPLICATION PROGRAMMING

LECTURER: MR. FRED OMONDI

QUIZ. Develop two systems that showcase the implementation of the following in vb.net;

 object
 class
 inheritance
 polymorphism

SOLUTION

Animal Hierarchy

This system demonstrates the concept of inheritance and polymorphism by creating a hierarchy of
animals.

Public Class Animal

Public Property Name As String


Public Sub New(name As String)

Me.Name = name

End Sub

Public Overridable Sub MakeSound()

Console.WriteLine("The animal makes a sound.")

End Sub

End Class

Public Class Dog

Inherits Animal

Public Sub New(name As String)

MyBase.New(name)

End Sub

Public Overrides Sub MakeSound()

Console.WriteLine("The dog barks.")

End Sub

End Class

Public Class snake

Inherits Animal

Public Sub New(name As String)

MyBase.New(name)

End Sub
Public Overrides Sub MakeSound()

Console.WriteLine("The snake hisses.")

End Sub

End Class

Module AnimalHierarchy

Sub Main()

Dim dog As New Dog("Buddy")

Dim snake As New snake("Whiskers")

dog.MakeSound()

cat.MakeSound()

End Sub

End Module

In this example, we have an Animal class as the base class, and Dog and snake classes that inherit from
Animal.

The Animal class has a Name property and a MakeSound method, which is marked as Overridable to
allow derived classes to override it.

The Dog and snake classes override the MakeSound method to provide their specific sound.

In the Main method, we create instances of Dog and snake and call their MakeSound methods.

OUT PUT

The dog barks.

The snake hisses.

SYSTEM TWO

Employee Management

This system shows the concept of objects and classes by creating an employee management system.
SOLUTION

Public Class Employee

Public Property Name As String

Public Property Salary As Decimal

Public Sub New(name As String, salary As Decimal)

Me.Name = name

Me.Salary = salary

End Sub

Public Overridable Function GetPay() As Decimal

Return Salary

End Function

End Class

Public Class Manager

Inherits Employee

Public Property Bonus As Decimal

Public Sub New(name As String, salary As Decimal, bonus As Decimal)

MyBase.New(name, salary)

Me.Bonus = bonus

End Sub

Public Overrides Function GetPay() As Decimal

Return Salary + Bonus

End Function
End Class

Module EmployeeManagement

Sub Main()

Dim employee1 As New Employee("Alfred", 5000)

Dim employee2 As New Manager("Adede", 5000, 10000)

Console.WriteLine("Employee 1 Pay: " & employee1.GetPay())

Console.WriteLine("Employee 2 Pay: " & employee2.GetPay())

End Sub

End Module

In this example, we have an Employee class as the base class and a Manager class that inherits from
Employee.

Both classes have Name and Salary properties. The Employee class has a GetPay method,

and the Manager class overrides it to include the Bonus property in the calculation. In the Main method,
we

create instances of Employee and Manager and call their GetPay methods. The output will be:

OUTPUT

Employee 1 Pay: 5000

Employee 2 Pay: 15000

You might also like