java面向对象------- object类及toString方法的重写

package java面向对象;

/**
* 测试object类
*/
public class TestObject extends Object{

public String toString(){
return "测试重写";
}

public static void main(String[] args) {
TestObject to=new TestObject();
System.out.println(to.toString());

Person2 p2=new Person2("小红",18);
System.out.println(p2.toString());

}

}

class Person2{
String name;
int age;
public String toString(){
return name+"年龄"+age;
}
public Person2(String name,int age){
this.name=name;
this.age=age;
}

}
posted on 2019-05-19 15:45  zz测试笔记  阅读(301)  评论(0编辑  收藏  举报