If one class is derived from another that is derived from Object, is that “multiple inheritence”

前端 未结 7 1487
没有蜡笔的小新
没有蜡笔的小新 2021-01-29 09:56

The fact about Java is that it does not support the multiple inheritance.

But I have a question that the base class of all java classes is Object.

Now we have tw

相关标签:
7条回答
  • 2021-01-29 10:06

    class B inherits from class A which in turn inherits from Object. Object is at top of the inheritance hierarchy. This is multi level inheritance , not multiple inheritance.

    0 讨论(0)
  • 2021-01-29 10:07

    Object class is base class of all other classes.Here when you inherit class B from class A then class B can not be inherit from Object class.

    public class B extends class A
    {
    
    }
    

    And here, base class of class A is Object class.

    So in short, if we not inherit any class then its base class would be object class.

    You can also refer this:

    http://docs.oracle.com/javase/tutorial/java/concepts/inheritance.html

    0 讨论(0)
  • 2021-01-29 10:11

    What you describe is not multiple inheritance; B inherits from a single super class, A and A inherits from a single super class, Object. B gains the properties and methods of both A and Object, but this is via a single 'chain'of inheritance.

    Multiple inheritance is where a class inherits directly from more than one, unrelated class. This is not possible in Java.

    0 讨论(0)
  • 2021-01-29 10:15

    A, and B inherits Object so A inherits Object when inherits B.

    0 讨论(0)
  • 2021-01-29 10:16

    Think of inheritance as an "is a" relation.

    In Java we can have

    A dog is a mammal is an animal

    but not

    A dog is a mamal and a four legged animal

    mammal and four leggeld animal are at the same level but mammal and animal are at different levels.

    The reason we can have the first but not the second is if we know that mammals talk in a certain way, animals talk in a certain way and four legged animals talk in a certain way we can work out the way dogs talk unambiguously in the first case but not the second.

    0 讨论(0)
  • 2021-01-29 10:22

    A class always extends only one class. That is the Object class or the class defined with the extends keyword. That class in turn can extend also only one class until eventual the Object class is reached.

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