Friday, December 28, 2007

OOP: VB.Net Inheritance

Being an object oriented language, Visual Basic has the ability to derive one class from a parent class. Inheritance enables code reuse, as well as a way to express hierarchial relationships. This is accomplished in code by using the 'Inherits' keyword.

The following shows a simple illustration of inheritance. Notice the use of Access Modifiers discussed previously.
Public Class Automobile
Public wheelCount as Integer
End Class

Public Class SportsCar
Inherits Automobile

Public turboCharged as Boolean
End Class

Public Class HotRod
Inherits SportsCar

Public parachuteEnabled as Boolean
End Class

No comments: