日期:2014-05-20  浏览次数:20599 次

请各位帮一下忙!!!
public   class   c1{
public   static   void   main(String[]   args)
{
c1   k=new   c1();
System.out.println(k);
}  
}
为什么上面的程序输出的结果是c1@35ce36?
public   class   c1{
int   i;
int   b=5;
int   c=7;
void   f(){System.out.println(i);}
void   g(){i=1;}
void   h(){System.out.println(c);}
public   static   void   main(String[]   args)
{
c1   k=new   c1();
System.out.println(k);
}  
}
为什么上面的程序和第一个程序输出的结果一样?


------解决方案--------------------
你这两个类 都是从object继承而来的。。都没有覆盖tostring方法 所以再输出对象的时候 调用的是object的tostring方法。。是类名+@+对象哈希码(hashcode)的无符号十六进制
c1 @ 35ce36