I just read some where that C# class can't inherit from multiple class, at the same time I also read that each C# class is inherited from a base class "Object Class".
Now I am confused if I make another class make it to inherit some class, then it is inheriting from the class and the base class, ie two class.
Isn't it breaking the law?
Each class inherits from one other class. If you make your own class extend one of your other classes, then it will not directly inherit from Object but rather from your superclass. The superclass in its turn will inherit from Object.
Your subclass will have all the methods from Object available trough the superclass.
This will illustrate it:
void Main()
{
Console.WriteLine (new Super().GetType().BaseType);
Console.WriteLine (new Sub().GetType().BaseType);
}
class Super { }
class Sub : Super { }
Output:

This is possible in C#:

(One base class per derived class, aka "single inheritance")
This is not possible in C#:

(Multiple inheritance, use interfaces instead in C#)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With