1234567891011121314151617181920212223242526272829303132333435/** * 测试Object类并重写toString * @author 葛宇 */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; }}