Adv App Prog Assign
Adv App Prog Assign
REG: 19/02741
COURSE: BSD
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.
Me.Name = name
End Sub
End Sub
End Class
Inherits Animal
MyBase.New(name)
End Sub
End Sub
End Class
Inherits Animal
MyBase.New(name)
End Sub
Public Overrides Sub MakeSound()
End Sub
End Class
Module AnimalHierarchy
Sub Main()
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
SYSTEM TWO
Employee Management
This system shows the concept of objects and classes by creating an employee management system.
SOLUTION
Me.Name = name
Me.Salary = salary
End Sub
Return Salary
End Function
End Class
Inherits Employee
MyBase.New(name, salary)
Me.Bonus = bonus
End Sub
End Function
End Class
Module EmployeeManagement
Sub Main()
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