package nn; public class RL{ private String name; private int age; public RL(String name,int age){ this.name =name; this.age =age; } public boolean compare(RL r) { if(this.name.equals(r.name)&&this.age==r.age) { return true; }else { return false; } } public String getName() { return this.name; } public int getAge() { return this.age; } }
package nn; public class CRL { public static void main(String args[]) { RL r1 = new RL("张三",30); RL r2 = new RL("张三",30); if(r1.compare(r2)) { System.out.println("r1和r2"); System.out.println("是同一个人"); } } }
package nn; public class ren { private int age; private String name; public ren(String name,int age) { this.name =name; this.age =age; } public boolean compare(ren l) { if(this==l) { return true; } if(this.name.equals(l.name)&&this.age==l.age) { return true; }else { return false; } } public String getName() { return this.name; } public int getAge() { return this.age; } }
package nn; public class lei { public static void main(String args[]) { ren l1 = new ren("张三",20); ren l2 = new ren("张三",20); if(l1.compare(l1)) { System.out.println("是同一个人"); } } }
package nn; class ee { private String name; private int age; public ee(String name,int age) { this.name = name; this.age = age; } public void fun(ee te) { te.name ="lucy"; te.age =23; } public String getName() { return this.name; } public int getAge() { return this.age; } }
package nn; public class Cdmo { public static void main(String args[]) { ee son =new ee("tony",22); son.fun(son); System.out.println(son.getName() + "-->" +son.getAge()); } }
package nn; public class qq { private String name; private String age; public qq(String name,String i){ this.name=name; this.age=i; } public qq(String name2,int i) { } public String getName() { return this.name; } public String getAge() { return this.age; } }
package nn; public class sdf { public static void main(String args[]){ qq per1 = new qq("理想",21); qq per2 = new qq("理想",21); { System.out.println("是同一个人!!"); } } };