问题
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 two classes : Class A and Class B. B is inherited from A then the Base class of B would be the Object and A , so here, the multiple inheritance took place.
Anyone will please help me to clear my doubt?
回答1:
The concept of Multiple Inheritance
means, that you can have a class A, B and C where A is derived from B and C like this:
class A extends B, C {}
This is not possible in Java.
What you describe is a straightforwar inheritance with a direct line of descendenats.
class A {};
class B extends A {}
class C extends B {}
You don't really need Multiple Inmheritance though, because with Interfaces
you can basically achieve the same in a much cleaner way.
回答2:
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.
回答3:
A, and B inherits Object so A inherits Object when inherits B.
回答4:
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.
回答5:
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.
回答6:
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
回答7:
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.
来源:https://stackoverflow.com/questions/17364076/if-one-class-is-derived-from-another-that-is-derived-from-object-is-that-multi