//object常用方法
public class test21 {public static void main(String[] args) {Object obj = new Object();ObjectCl usr = new ObjectCl();usr.setAge(6);usr.setName("歌谣");usr.say();//tostringString str =usr.toString();System.out.println(str);//equalsObjectCl usr2=new ObjectCl();boolean bool=usr2.equals(usr);System.out.println(bool);//getclassSystem.out.println(usr.getClass());//hashcodeSystem.out.println(usr.hashCode());}
}
public class ObjectCl {private String name;private int age;public void say(){System.out.println(name);System.out.println(age);}public void setAge(int age) {this.age = age;}public int getAge() {return age;}public void setName(String name) {this.name = name;}public String getName() {return name;}@Overridepublic String toString() {return this.getClass().getName();}public boolean equals(Object obj){return this==obj?false:true;}
}
运行结果