class A//所有的类默认继承Object,里面有toString()
{
public String toString()
{
retutn "哈哈";//重写父类方法
}
}
public class TestObject
{
public static void main(String[] args)
{
A aa = new A();
System.out.printf("%s\n",aa.toString());
}
{
public String toString()
{
retutn "哈哈";//重写父类方法
}
}
public class TestObject
{
public static void main(String[] args)
{
A aa = new A();
System.out.printf("%s\n",aa.toString());
}
}
--------------------------------------------------------------------------
class Dian
{
public int x,y;
public Dian(int x,int y)
{
this.x = x;
this.y = y;
}
public String toString()
{
return "[" + x + "," + y +"]";
}
}
public class TestPoint
{
public static void main(String[] args)
{
Dian d = new Dian(1,2);
System.out.printf("%s",d);//d表示把对象类名和地址输出,相当于d.toString();
}
}