Posted by : Sudhir Chekuri Saturday, 5 October 2013

VB.NET Interface multiple inheritance

Multiple inheritance of classes is not supported in VB.NET because of ambuiguity problem and it replaced using concept called interfaces.
Interface will contain only abstract methods and the methods inside interface should be implemented in the class which inherits it.
We can inherit more than one interface at once which is known as multiple inheritance.
All the methods in interface is by default public.

VB.NET interfaces multiple inheritance program

Module Module1
    'create interface
    Public Interface i1
        Sub print1()
    End Interface
    Public Interface i2
        Sub print2()
    End Interface
    'create derived class
    Public Class class1
        Implements i1, i2

        Public Sub print1() Implements i1.print1
            Console.WriteLine("Interface 1 is calling")
        End Sub

        Public Sub print2() Implements i2.print2
            Console.WriteLine("Interface 2 is calling")
        End Sub
        Public Sub print3()
            Console.WriteLine("Class1 is calling")
        End Sub
    End Class

    Sub Main()
        Dim c1 As New class1()
        c1.print1()
        c1.print2()
        c1.print3()
        Console.ReadLine()
    End Sub

End Module

Output

Interface 1 is calling
Interface 2 is calling
Class1 is calling


Leave a Reply

Subscribe to Posts | Subscribe to Comments

Followers

Total Pageviews

Powered by Blogger.

Blog Archive

- Copyright © 2013 DevStudent - Metrominimalist - Powered by Blogger - Designed by Johanes Djogan -