Polymorphism

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 ...

Get Visual Basic® .NET by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.