天天看点

System.out.println()方法

假设有一个实例Object o,

则当System.out.println(o);时,它其实是自动调用o.toString()方法,然后输出该方法

返回的string字符串.

当System.out.println(o.toString());时,输出字符串的格式为"类名+@+该对象(o)的地址"

当System.out.println(o.getClass().toString());时,输出字符串的格式为"class  +类名"

Test.java

public class Test

{

    public static void main(String[] args)

    {

        Test test=new Test();

        System.out.println(test);

        System.out.println(test.toString());

        System.out.println(test.getClass().toString());

    }

}