比较两个对象是否相等demo
package String; /* * 写了一个简单的demo 比较两个对象是否相等 */ public class StringDemo5 { public static void main(String[] args) { personuu re = new personuu("lisi",78); personuu tr = new personuu("lisi",78); if(re.getname().equals(tr.getname()) && re.getage()==tr.getage()){ System.out.println("bigo"); } else { System.out.println("waoo"); } } } class personuu{ private String name; private int age; public void setname(String name) { this.name = name; } public void setage(int age){ this.age = age; } public String getname() { return name; } public int getage() { return age; } public personuu() { //无参构造 } public personuu(String name,int age) { this(); //在此处调用person类中的无参构造方法 setname(name); setage(age); } }