Polymorphism

Polymorphism is a facility supported by Visual Basic .NET. Polymorphic behavior occurs when you declare a parent type and instantiate a child type. The compiler adds code to resolve the actual method that needs to be called by the instance of the object.

Continuing the plane example, we could add a MultiEngineLand plane to our plane class. Operations that use the same code to work with both kinds of plane could be written in one procedure. If we defined the parameters to the procedure to take a Plane, we could pass any subclass of plane to the procedure.

Polymorphic behavior is generally needed when you see code that takes an action based on a case statement evaluating a type code. Let's step back and look at polymorphism relative ...

Get Visual Basic® .NET 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.