System.Object being the base class

后端 未结 8 999
北荒
北荒 2020-12-03 15:47

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

相关标签:
8条回答
  • 2020-12-03 15:55

    Class A inherits from System.Object. Class B inherits from class A, which inherits from System.Object

    0 讨论(0)
  • 2020-12-03 16:11

    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).

    0 讨论(0)
  • 2020-12-03 16:12

    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#.

    0 讨论(0)
  • 2020-12-03 16:15

    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
    {
    }
    
    0 讨论(0)
  • 2020-12-03 16:17

    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.

    0 讨论(0)
  • 2020-12-03 16:17

    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."

    0 讨论(0)
提交回复
热议问题