The concept of a class makes it possible to define subclasses that share some or all of the main class characteristics. This is called inheritance. Inheritance also allows you to reuse code more efficiently. In a class tree, inheritance is used to design classes vertically. (You can use Interfaces to design classes horizontally within a class tree.) With inheritance, you are defining an "is-a" relationship (i.e. a chow is-a dog). Analysts using UML call this generalization where you generalize specific classes into general parent classes.
VB.Net Inheritance
VB.Net uses the Inherits keyword followed by the parent class name. If you do not include Inherits, your class inherits from System.Object.
Syntax Example:
In the following example, a terminator T-600 is-an android.
Public Class Android
End Class
Public Class T-600
Inherits Android
End Class
When designing classes and creating (instanciating) objects in VB.Net, you use the Inherits keyword to signify what class to inherit from. VB.Net supports single inheritance so you have to specify a single class (you cannot specify more than one parent class).
Class Scope Specifiers
Private, Protected, and Public Members
In most OOP languages, private, protected, and public members have a specific scope:
Private = Used by the defining class only. Invisible outside of the class except by friendly classes.
Protected = Used by the defining class and descendant classes only (plus friendly classes).
Public = Visible wherever its class can be referenced.
The following are practice certification questions with answers highlighted. These questions were prepared by Mike Prestwood and are intended to stress an important aspect of this KB post. All our practice questions are intended to prepare you generally for passing any certification test as well as prepare you for professional work.