[英]Can we add the more methods in Object class of java?
We all know that Object
class is the super class in Java. 我们都知道
Object
类是Java中的超类。 Can we add methods into the Object
class? 我们可以在
Object
类中添加方法吗? And, if we make a new class with the name Object
then will the functionality of that class affect the super class Object
? 并且,如果我们使用名称
Object
创建一个新类,那么该类的功能会影响超类Object
吗?
Can we add methods into the
Object
class?我们可以在
Object
类中添加方法吗?
No. You can subclass it, but you cannot modify it (without modifying the JDK's and JRE's runtime jars; which is a Bad Idea™ ). 不可以。您可以对其进行子类化,但不能对其进行修改(不修改JDK和JRE的运行时jar;这是Bad Idea™ )。
And, if we make a new class with the name
Object
then will the functionality of that class affect the super classObject
?并且,如果我们使用名称
Object
创建一个新类,那么该类的功能会影响超类Object
吗?
No, they'll be separate classes. 不,它们将是单独的类。 Of course, calling a class
Object
would be confusing and surprising to people reading the code. 当然,对于阅读代码的人来说,调用类
Object
会感到困惑和惊讶。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.