JAVA研发面试题(基础)
JAVA基础(目录): Object类的方法,逐个解释一下(clone,hashCode,equals,wait,finalize,notify) Java的Exception类型 Integer和int有啥区别,integer中有哪些特殊的函数? 说一下String实现 intern final 关键字 序列化,远程方法调用
Object类的方法
public class Object {
private static native void registerNatives();
static {
registerNatives();
}
public final native Class<?> getClass();
public native int hashCode();
public boolean equals(Object obj) {
return (this == obj);
}
protected native Object clone() throws CloneNotSupportedException;
public String toString() {
return getClass().getName() + "@" + Integer.toHexString(hashCode());
}
public final native void notify();
public final native void notifyAll();
public final native void wait(long timeout) throws InterruptedException;
public final void wait(long timeout, int nanos) throws InterruptedException {
if (timeout < 0) {
throw new IllegalArgumentException("timeout value is negative");
}
if (nanos < 0 || nanos > 999999) {
throw new IllegalArgumentException(
"nanosecond timeout value out of range");
}
if (nanos > 0) {
timeout++;
}
wait(timeout);
}
public final void wait() throws InterruptedException {
wait(0);
}
protected void finalize() throws Throwable { }
}
只有继承了Object类的对象
clone–native方法/可以重写
protected native Object clone() throws CloneNotSupportedException;
基本数据类型(八种:byte-1个字节、short-2个字节、int-4个字节、long-8个字节、float-4个字节、double-8个字节、bool
本文介绍了JAVA中Object类的几个重要方法,包括clone(浅复制与深复制)、hashCode(返回对象的哈希码)、equals(比较对象的相等性)、toString(返回对象的字符串表示)、wait/notify/notifyAll(线程通信)以及finalize(对象回收前的操作)。讲解了这些方法的默认行为、可重写性以及在不同场景下的应用。
最低0.47元/天 解锁文章
Object中的方法-clonehashCodeequalstostringwait-notify-notifyallfinalize&spm=1001.2101.3001.5002&articleId=88535199&d=1&t=3&u=5019ddb8f4ce4aefaab791eb43895970)
1169

被折叠的 条评论
为什么被折叠?



