既然所有的Java类都继承自父类(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.
也在Oracle docs中
Class Object is the root of the class hierarchy. Every class has Object as a superclass
因此,每个对象都具有来自 Object
类的属性,例如 public String toString()
方法。
关于java - 如果我说所有 Java 对象都是多态的,对吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66437524/