Home >>VB.Net Built-in Functions >VB.Net Program to demonstrate the multi-level inheritance
Here, by demonstrate three classes, Sample1, Sample2, Sample3, we can show the multilevel inheritance. Here, the parent class for Sample2 will be Sample1 and the parent class for Sample3 will be Sample2.
Program :The source code to demonstrate the multi-level inheritance is given below. The program given is successfully compiled and executed.
'VB.net program to demonstrate the multi-level inheritance.
Module Module1
Class Sample1
Sub Fun1()
Console.WriteLine("Sample1.Fun1() called")
End Sub
End Class
Class Sample2
Inherits Sample1
Sub Fun2()
Console.WriteLine("Sample2.Fun2() called")
End Sub
End Class
Class Sample3
Inherits Sample2
Sub Fun3()
Console.WriteLine("Sample3.Fun3() called")
End Sub
End Class
Sub Main()
Dim obj As New Sample3()
obj.Fun1()
obj.Fun2()
obj.Fun3()
End Sub
End Module
We have created a Module1 module in the program above. Here, three classes have been created: Sampl1, Sample2 and Sample3. Here, Sample1 is the parent class of Sample2 and Sample2 is the parent class of Sample3. Each class contains a method.
At last, we created a Main() function, it is the entry point for the program, here we created the object of Sample3 class, and called methods fun1(), fun2(), fun3(). All the methods will print a message on the console screen.