package ObjectDemo;
import java.util.Objects;
public class Application {
public static void main(String[] args) {
Demo01 demo01 = new Demo01(10, "张三");
Demo01 demo02 = new Demo01(20, "李四");
Demo01 demo04 = new Demo01(20, "李四");
//判断demo1 和 demo2 是不是一个类型 ,get.Class方法
Class class1 = demo01.getClass();
Class class2 = demo02.getClass();
if (class1 == class2) {
System.out.println("是一个类");
} else {
System.out.println("不是一个类");
}
System.out.println("=========================");
//判断内存是否相等,hashCode
System.out.println(demo01.hashCode());
System.out.println(demo02.hashCode());
Demo01 demo03 = demo01;
System.out.println(demo03.hashCode());
System.out.println("==========================");
//tostring方法,可以在子类重写。因为不满足需求
System.out.println(demo01.toString());
System.out.println(demo02.toString());
System.out.println(demo03.toString());
System.out.println("==========================");
//equals,判断两个对象是否相等.不滿足需求重寫
System.out.println(demo01.equals(demo02));
System.out.println(demo03.equals(demo01));
System.out.println(demo02.equals(demo04));
System.out.println("==========================");
//回收没用的垃圾
new Demo01(10, "张三");
new Demo01(20, "李四");
new Demo01(20, "王五");
System.gc();
}
}
标签:第九天,demo01,System,Demo01,println,new,out From: https://www.cnblogs.com/inian/p/18002220