Q

Why is VB.NET considered truly object-oriented, but VB6 isn't?

Why is VB.NET considered truly object-oriented? And why was VB 6.0 not considered to be so?
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.

This was last published in November 2002

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchCloudComputing

SearchSoftwareQuality

SearchSOA

TheServerSide

SearchCloudApplications

Close