1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
package 面向对象核心;
public class TestObject { public static void main(String[] args) { TestObject obj = new TestObject(); System.out.println(obj.toString()); People ple = new People("Kevin",18); System.out.println(ple); } @Override public String toString() { return "测试Overtide Object类的toString方法"; } }
class People{ int age; String name; @Override public String toString() { return name+" 年龄:"+age; } public People(String name,int age) { this.name = name; this.age = age; } }
|