标题:[求助]请教关于对象克隆的问题!!
取消只看楼主
向着梦想加速
Rank: 1
等 级:新手上路
帖 子:82
专家分:0
注 册:2007-9-18
 问题点数:0 回复次数:0 
[求助]请教关于对象克隆的问题!!
请问一下,我的程序为什么会编译不了??
但如果把第9行删除,并把第61行的注释取消,则程序就可以运行!!
class lian
{
public static void main(String []args)
{
teacher z=new teacher("李老师",50);
student x=new student("pet",20,z);
student y=x.clone();
y.name="petpet";
teacher y.z=z.clone(); //第9行
y.z.name="Mr Li";
System.out.println(y.name);
System.out.println(z.name);
}
}
class teacher implements Cloneable
{
int age;
String name;
teacher(String name,int age)
{
this.name=name;
this.age=age;
}
public teacher clone()
{
teacher q=null;
try
{
q=(teacher)super.clone();
}
catch(CloneNotSupportedException e)
{
e.printStackTrace();
}
return q;
}
}
class student implements Cloneable
{
int age;
String name;
student o;
teacher z;
student(String name,int age,teacher z)
{
this.name=name;
this.age=age;
this.z=z;
}
public student clone()
{
student o=null;
try
{
o=(student)super.clone();
}
catch(CloneNotSupportedException e)
{
e.printStackTrace();
}
//o.z=(teacher)z.clone(); //第61行
return o;
}
}
搜索更多相关主题的帖子: 对象 克隆 
2007-09-27 23:32



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-173459-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.029265 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved