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

引用@hashcode,如何解释?如何转换为对象名?
class clsEmployee{
String ID;
String Name;
clsEmployee(String id,String name)
{
  ID=id;
  Name=name;
}
void printA(clsEmployee a)
{
  System.out.println("员工"+a+"的ID为:"+a.ID);
  System.out.println("员工"+a+"的姓名为:"+a.Name);
}
}
public class Employee{
public static void main(String[] args)
{
  clsEmployee A=new clsEmployee("001","张三");
  clsEmployee B=new clsEmployee("002","李四");
  A.printA(A);
  B.printA(B);
}
}
执行结果:
员工clsEmployee@757aef的ID为:001
员工clsEmployee@757aef的姓名为:张三
员工clsEmployee@d9f9c3的ID为:002
员工clsEmployee@d9f9c3的姓名为:李四

问题:clsEmployee@757aef、clsEmployee@d9f9c3应该是:引用@hashcode,如何解释?如何转换为对象名称"a"和"b"

------解决方案--------------------
打印对象实际上是输出其toString()方法的返回结果. 如果你没有实现, 那么调用Object.toString()方法, native的吧, 返回类名以及内存地址.