您的位置:首页 > 其它

System.out.println()方法

2009-10-01 20:37 204 查看
假设有一个实例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());
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: