简体   繁体   English

我们可以在Java的Object类中添加更多方法吗?

[英]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 class Object ? 并且,如果我们使用名称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.

相关问题 我们如何调用在Java匿名类中重写的方法? - How can we call methods overridden in a java anonymous class? Java:为什么我们可以从非子类访问字段和方法时需要扩展类 - Java: why we need to extend a class when we can access the fields and methods from non sub class 我们能否将 Arraylist 从 class 调用到另一个 class,并且可以被“另一个”class 中的所有方法使用? 无 static - Java - Can we call a Arraylist from a class to another class, and can be used by all methods in the 'another' class? No static - Java 我们如何在java中创建类Object类 - How can we create a class like Object class in java 我们可以创建一个不能从类中调用任何方法的类(超类或子类)的对象吗? - Can we create an object of a class (super or sub class) which cannot invoke any methods from the class? 在Java类中,我们是否为该类的每个对象都有单独的实例方法副本? - In a Java class, do we have separate copies of instance methods for each object of that class? Java中的String class可以添加新的方法吗? - Can I add new methods to the String class in Java? 我们如何使用java中的反射向现有类添加瞬态? - How can we add transient to existing class using reflection in java? 有多少变量,我们可以在java类中编写多少个方法,以及我们可以在java方法中编写多少行代码? - how many variables, how many methods can we write in java class and how many lines of code can we write in java method? 我们如何在Java中的第一个类中调用第二个调用的对象 - how we can call the object of second call in the first class in java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM