December 2001
Beginner
976 pages
22h 4m
English
Polymorphism comes from the Greek roots polu (many) and morphe (form), and it means (in computer science) an entity that can have multiple forms or different behavior. In the specific case of inheritance it means that derived classes may have different behavior for the same method.
Let's assume that you need to add a method that calculates the monthly salary of an employee. The normal place you would add this would be the Employee class, where you have the m_salary field, from which you calculate the income. You could write a function GetMontlyPay() as shown:
Public Class Employee Inherits Person Protected m_salary As Decimal ' the rest of the class is omitted (unchanged) Public Function GetMonthlyPay() As Decimal Return m_salary ...
Read now
Unlock full access