Constructor Overriding in Visual Basic .NET

In this lesson, I will show you how to do constructor overriding in VB.NET. We have base class named People and we have sub class named Student

Both the classes have constructors Public Sub New(). Inside the constructor you can see console message

This is the People Class

This is the Student Class

I have just created object p which is a instance of People and S instance of Student class

You can see the console output as below

When you create a object from subclass. It first call the base class constructor and then call the sub class constructor

Now I am going to add another constructor with one argument to Sub Class

Now I will change the main module as below

Changed only the Line 10. It passes the constructor argument when creating the object

Now you get the output

Leave a Reply

Your email address will not be published. Required fields are marked *