Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vb.net: multiple inheritance in an interface

I'm facing a problem regarding multiple inheritance in VB.net:

As far as I know VB.net does not support multiple inheritance in general but you can reach a kind of multiple inheritance by working with interfaces (using “Implements” instead of “Inherits”):

Public Class ClassName
    Implements BaseInterface1, BaseInterface2

End Class

That works fine for classes but I’d like to have an interface inheriting some base interfaces. Something like that:

Public Interface InterfaceName
    Implements BaseInterface1, BaseInterface2

End Interface

But the “Implements” keyword is not allowed for interfaces (what makes sense, of course). I tried to use a kind of abstract class which I know from Java:

Public MustInherit Class InterfaceName
    Implements BaseInterface1, BaseInterface2

End Class

But now I need to implement the defined methods from BaseInterface1 and BaseInterface2 within the InterfaceName class. But as InterfaceName should be an interface, too, I don’t want to have to implement these methods within that class.

In C# you can do that quite easy:

public interface InterfaceName: BaseInterface1, BaseInterface2 {}

Do you know if I can do something similar in VB.net?

like image 702
Erwin Avatar asked Apr 15 '11 20:04

Erwin


People also ask

Is multiple inheritance possible in interface?

An interface contains variables and methods like a class but the methods in an interface are abstract by default unlike a class. Multiple inheritance by interface occurs if a class implements multiple interfaces or also if an interface itself extends multiple interfaces.

Does VB net support multiple inheritance?

Unlike languages that allow multiple inheritance, Visual Basic allows only single inheritance in classes; that is, derived classes can have only one base class. Although multiple inheritance is not allowed in classes, classes can implement multiple interfaces, which can effectively accomplish the same ends.

Can we implement inheritance in interface in VB net?

An interface cannot inherit from an interface nested within it.

What is multilevel inheritance vb net?

Inheritance can have multiple levels. That is, a base class can have derived classes, each of which can have derived classes, and so on. These classes constitute what is known as an inheritance hierarchy (or inheritance tree).


1 Answers

Similar to Java, in VB.NET interfaces "extend" other interfaces. That means they "inherit" their functionality. They do not implement it.

Public Interface InterfaceName
    Inherits BaseInterface1, BaseInterface2
End Interface
like image 199
pickypg Avatar answered Sep 21 '22 08:09

pickypg