This question may be usual for many, i tried for an hour to understand the things but getting no proper explanation.
MSDN says, System.Object is the ultimate
Class A
inherits from System.Object. Class B
inherits from class A
, which inherits from System.Object
Correct, C# only allows single inheritence. The System.Object class is inherited implicitly by your Class A. So Class B is-a A, which is-a System.Object. This is taken care of by the compiler so you don't need to explicitly say that Class A : System.Object
(though you can if you want).
Multiple inheritance means that e.g. class A inherits from both class B and class C directly, like this:
class A : B, C
That doesn't work in C#. Your example means that you inherit from a class which itself inherits from another, like this:
class A : object
{
}
class B : A
{
}
That is possible in C#.
You can't inherit two classes, but you can inherit a hierarchy of classes.
System.Object
|
\-- Class A {}
|
\-- Class B {}
public class ClassA
{
}
public class ClassB : ClassA
{
}
public class ClassC : ClassB
{
}
Look, you can only have one father. But your father also can have a father. Thus, you inherit some attributes from your grandfather. Dog
class inherits from Mammals
, which in turn inherits from Animal
class, which in turn inherits from LivingThing
class.
Multiple inheritance means inheriting from multiple classes into one class. Your example is valid, but you wouldn't be able to do the following:
Class B : A,C { --- }
A definition for multiple inheritance:
"Multiple inheritance is a feature of some object-oriented computer programming languages in which a class can inherit behaviors and features from more than one superclass."