Inheritance Keywords

There are a number of keywords associated with inheritance. Remember that by default, all classes you create are inheritable. You inherit from classes using the Inherits keyword. The class from which you inherit is then known as the base class. The Inherits keyword can be used only in classes and interfaces. It is important to point out that a derived class can only inherit from one base class.

Forcing or Preventing Inheritance

The NotInheritable modifier is used to mark a class as not inheritable; in other words, it cannot be used as a base class. If you were to modify the Person class in your InheritanceTest project, it would look like this:

Public NotInheritable Class Person

If you change the Person definition to look ...

Get A Programmer's Introduction to Visual Basic® .NET 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.