Introducing Polymorphism

Polymorphism is another key concept in object-oriented programming (OOP). As its name implies, polymorphism enables an object to assume different forms. In .NET development, it means you can treat an object as another one, due to the implementation of common members. A first form of polymorphism is when you assign base classes with derived classes. For example, both Contact and Customer classes are derived of the Person class. Now consider the following code:

Dim c As New ContactDim cs As New Customer'C is of type ContactDim p As Person = c

The new instance of the Person class receives an assignment from an instance of the Contact class. This is always possible because Person is the parent of Contact (in which base is ...

Get Visual Basic 2015 Unleashed 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.