1、equals()
2、toString()
package com_package1; public class Person44 { private int age; public int getAge() { return age; } public void setAge(int age) { this.age = age; } Person44(int age) { this.age = age; } }
package com_package1; public class Person44Demo { public static void main(String[]args) { Person44 p = new Person44(44); System.out.println(p);//com_package1.Person44@4f1d0d如果输出的是引用类型的变量那么输出的是字符串 System.out.println(p.toString());//com_package1.Person44@4f1d0d } }
package com_package1; public class Person44 { private int age; public int getAge() { return age; } public void setAge(int age) { this.age = age; } Person44(int age) { this.age = age; } public String toString() { return "Person:"+age; } }
package com_package1; public class Person44Demo { public static void main(String[]args) { Person44 p = new Person44(44); System.out.println(p);//com_package1.Person44@4f1d0d如果输出的是引用类型的变量那么输出的是字符串 System.out.println(p.toString());//com_package1.Person44@4f1d0d } }