java和超类中的继承(Object, Class) [英] Inheritance in java and Superclasses(Object, Class)
问题描述
java.lang.Object
是否隐式继承了所有自定义类/对象的超类?我以为java不支持多重继承.我问的原因是我是否已经从我的自定义类中的另一个类继承,并且再次 java 强制隐式继承 java.lang.Object
在它之上,它不是多重继承吗?
Is java.lang.Object
superclass of all the custom class/objects inherited implicitly? I thought java didn't support multiple inheritance. The reason I ask is if I already inherit from another class in my custom class and again java is forcing implicit inheritance of java.lang.Object
on top of it, is it not multiple inheritance?
此外,java.lang.class Class 是否也是所有自定义类/对象的超类?如果没有,我们如何在 Java 反射中获取传递的任何类的类类型或在任何对象上调用 isInstance?
Also, is java.lang.class Class also the superclass for all custom classes/Objects? If not, how in java reflections we can get the type of class for any class passed or call isInstance on any object?
推荐答案
Everything is an Object,也就是说你可以看到这样的结构:
Everything is an Object, that said you could see the structure as this:
Object
Animal
Cat
而不是这样:
Object Animal
Cat
Cat
扩展两者的地方,它不像最后一个例子,但 Cat
是 extends
Animal
extends
Object
.
Where Cat
extends both, it's not like this last example, but it's Cat
that extends
Animal
which extends
Object
.
这篇关于java和超类中的继承(Object, Class)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!