如果我说所有 Java 对象都是多态的,是否正确?
Is it correct if I say that all Java objects are polymorphic?
既然所有Java classes都继承自super-class Object,我们是否可以得出所有Java对象是多态的?
是的,完全正确。
如this tutorial
所述
In Java, all Java objects are polymorphic since any object will pass
the IS-A test for their own type and for the class Object.
Class Object is the root of the class hierarchy. Every class has
Object as a superclass
因此每个对象都具有来自 Object
class 的属性,例如 public String toString()
方法。
既然所有Java classes都继承自super-class Object,我们是否可以得出所有Java对象是多态的?
是的,完全正确。
如this tutorial
In Java, all Java objects are polymorphic since any object will pass the IS-A test for their own type and for the class Object.
Class Object is the root of the class hierarchy. Every class has Object as a superclass
因此每个对象都具有来自 Object
class 的属性,例如 public String toString()
方法。