package Test;
public class Test7 {
public static void main(String[] args) {
Object o1 = new Object();
Object o2 = new Object();
boolean b1 = o2.equals(o1); //判断两个对象的地址值是否相同,相同则返回true。子类继承时可以对它进行重写
System.out.println(b1);
Class<? extends Object> c1 = o1.getClass(); //返回此 Object 的运行时类。返回的 Class 对象是由所表示类的 static synchronized 方法锁定的对象。
System.out.println(c1); //也就是说一个类有且仅有一个运行时类
int i1 = o1.hashCode(); //返回该对象的哈希码值。子类继承时可以对它进行重写
System.out.println(i1);
String s1 = o1.toString(); //返回该对象的字符串表示。子类继承时可以对它进行重写
/*public String toString() {
return getClass().getName() + "@" + Integer.toHexString(hashCode());
}*/ //这是它的底层代码
System.out.println(s1);
//public final void notify()
//唤醒在此对象监视器上等待的单个线程。
//public final void notifyAll()
//唤醒在此对象监视器上等待的所有线程。
//public final void wait()
//在其他线程调用此对象的 notify() 方法或 notifyAll() 方法前,导致当前线程等待。
//public final void wait(long timeout)
//在其他线程调用此对象的 notify() 方法或 notifyAll() 方法,或者超过指定的时间量前,导致当前线程等待。
//public final void wait(long timeout, int nanos)
//在其他线程调用此对象的 notify() 方法或 notifyAll() 方法,或者其他某个线程中断当前线程,或者已超过某个实际时间量前,导致当前线程等待。
}
}
【java基础】【Object的主要方法】
最新推荐文章于 2024-07-30 14:53:52 发布