I read that VB.NET allows only single inheritance, i.e. a class can't inherit from more than one class.
Does every class not inherit from the base system class? and if so does this not count?
Hi,
it's not just that VB.NET wouldn't allow but the CLR (Common Language Runtime) and therefore all managed programming languages do not support it.
Every class inherits from System.Object or from a class which ultimately derives from System.Object. If you specify a class like
Public Class Sample
End Class
It derives from System.Object out-of-the box . Therefore it is the same as
Public Class Sample
Inherits System.Object
End Class
If you create second class
Public Class MySample2
Inherits MySample
End Class
Now, MySample2 inherits from MySample which inherits from System.Object. This way you can have classes which derive from other classes but ultimately every class derives from System.Object.
You can have multiple inheritance in .NET but that's implemented with interfaces.
So in your example
Public Class MySample2
Inherits MySample
End Class
could be rewritten as the following, could it?
Public Class MySample2
Inherits System.Object
Inherits MySample
End Class
and therefore Class MySample2 inherits from 2 classes, doesn't it?
Or is this not allowed, and the way to get round it is almost to build up a series of derived classes?
Hi,
As told by joteke, there is no multiple inheritance, with .net supported languages.
Have a look at this
A plea for full multiple inheritance support in .NET
Thanks
michaelcode:
So in your example
Public Class MySample2
Inherits MySample
End Classcould be rewritten as the following, could it?
Public Class MySample2
Inherits System.Object
Inherits MySample
End Classand therefore Class MySample2 inherits from 2 classes, doesn't it?
Or is this not allowed, and the way to get round it is almost to build up a series of derived classes?
To continue what e_screw and I on previous post(s) commented, that is not allowed.
thanks guys.
What I'm really trying to get at is, is the system object imported implicitly for all classes? as I've read that all classes derive from the system object.
0 comments:
Post a Comment