O'Reilly logo

Visual Basic® .NET by Example by Bob Donald, Gabriel Oancea

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required