Defining Classes That Cannot Be Subclassed

When a branch of your class hierarchy comes to a point and you want to ensure that no further inheritance occurs, you can define a final class.

A final class is a class that has the NotInheritable modifier in the class statement. For example, if we wanted to indicate that no child class can be derived from the SingleEngineLand plane, we could introduce the NotInheritable keyword, revising the class statement as follows:

Public NotInheritable Class SingleEngineLand

With that done, consumers can no longer subclass SingleEngineLand planes.

Using modifiers like NotInheritable or MustInherit is like using access specifiers Public, Private, Protected, or Friend, in that you can elect not to use them. Make ...

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.