
Implementation Inheritance
The major news in regards to OO development is that VB supports inheritance. The concept of inheritance is
simple, but the details are not. VB added many new keywords and constructs to help support inheritance. In
this section, you will see how you can use inheritance and examine all the associated VB keywords to build an
object hierarchy.
Inheritance allows a new class to reuse the attributes and behaviors from another class.
• The new class is said to be a “derived class.”
• The existing class is the “base class.”
• The derived class can accept the base class behaviors as is, or it can modify and extend them.
Inheritance models an “is-a” relationship. You can read the diagram below as “SalesPerson derives from
Employee.” Or you can say, “SalesPerson is a type of Employee.”
The basic syntax for deriving a class is shown below. Recall from Chapter 2 that the Inherits keyword is used
to mark a base or derived class relationship. Note that you can mark a class as NotInheritable if it should not
be used as a base class. C# calls these “sealed.” Java calls them “final.”
' A parent class.
Public Class TheBaseClass
Public Sub MethodInBase()
End Sub
End Class
' Derive class. This new class now has
' a method called MethodInBase().
Public Class TheDerivedClass
Inherits TheBaseClass
End Class
' This class can NOT be the base for other classes!
NotInheritable Public Class TheEnd
End Class
' Error! Can’t derive from a non-inheritable class!
Public Class TryAnyway
Inherits TheEnd
End Class
Implementation Inheritance: A Complete Example
To demonstrate inheritance constructs, you will implement the design below. The following is a simplified
UML diagram. Each “box” represents a class that defines the class name, fields, and method set.
Copyright (c) 2008. Intertech, Inc. All Rights Reserved. This information is to be used exclusively as an
online learning aid. Any attempts to copy, reproduce, or use for training is strictly prohibited.
Inheritance
Table of Contents
Courseware
Training Resources
Tutorials
Services