clone问题import java.util.*;public class Clonetest{\x05public
clone问题
import java.util.*;
public class Clonetest
{
x05public static void main(String[] srgs)
x05{
x05x05try
x05x05{
x05x05x05employee original=new employee("jony",50000);
x05x05x05original.sethireday(2000,1,1);
x05x05x05employee copy=original.clone();
x05x05x05copy.setsalary(10);
x05x05x05copy.sethireday(2002,12,31);
x05x05x05System.out.println("original:"+original);
x05x05x05System.out.println("copy:"+copy);
x05x05}
x05x05catch(CloneNotSupportedException e)
x05x05{
x05x05x05e.printStackTrace();
x05x05}
x05}
x05
}
class employee implements Cloneable
{
x05public employee(String n,double s)
x05{
x05x05name=n;
x05x05salary=s;
x05x05hireday=new Date();
x05}
x05
x05public employee clone() throws CloneNotSupportedException
x05{
x05x05employee cloned=(employee)super.clone();
x05x05cloned.hireday=(Date)hireday.clone();
x05x05return cloned;
x05}
x05
x05public void sethireday(int year,int month,int day)
x05{
x05x05Date newd=new GregorianCalendar(year,month-1,day).getTime();
x05x05hireday.setTime(newd.getTime());
x05}
x05public void setsalary(double p){salary+=salary*p/100;}
x05
x05public String toSting(){return "employee[name:"+name+",salary:"+salary+",hireday:"+hireday+"]";}
x05
x05private Date hireday;
x05private double salary;
x05private String name;
}
这是书上的,
System.out.println("original:"+original);
System.out.println("copy:"+copy);
是想输出什么?toString()为什么没有用
可是这里面有重写toString()方法啊
,public String toSting(){return "employee[name:"+name+",salary:"+salary+",hireday:"+hireday+"]";}
为什么输出的是
original:p215.employee@14318bb
copy:p215.employee@ca0b6