Q. Why is VB.NET considered truly object-oriented? And why was VB 6.0 not considered to be so?

Asked by reader. Answered by the Wonk on November 5, 2002

A.

VB6 is considered “object-based” because it supports classes and objects but not inheritance. Inheritance allows a class to get fields and methods from a base class, like this sample in VB.NET:

 

' Base class

Class Dog

  Public Sub Bark()

    MessageBox.Show("Woof")

  End Sub

End Class

 

' Derived class

Class BigDog

  ' Inherit all members from base class Dog

  Inherits Dog

 

  ' Add new member

  Public Sub EatCat()

    MessageBox.Show("Munch")

  End Sub

End Class

 

Module App

  Sub Main()

    ' Create an instance of the derived class

    Dim fido As BigDog = New BigDog()

 

    ' Call a method from the base class

    fido.Bark()

  End Sub

End Module

 

Inheritance is a powerful feature of reuse, allowing you to factor shared functionality between classes into a base class, reusing them in specific derived classes. While there are other new object-oriented features new to VB.NET, inheritance, long present in languages like C++ and Java, is the key new feature in VB.NET that makes it object-oriented instead of object-based.

Feedback

I have feedback on this Ask The Wonk answer