to kamanwu(kaman)
错误边变为:
test.java:27: clone() has protected access in java.lang.Object
item2=(String)item1.clone();
^
错误边变为:
test.java:27: clone() has protected access in java.lang.Object
item2=(String)item1.clone();
^
调试欢乐多
如果你要用的话,写一个String的继承类。
item是String,而它为什么就不能使用String的protected方法呢?可以再解释
详细些吗?
extends ObjectString不能被extend.protected方法再它的子类中能用。但是你的程序不能用。public才可以。
public String strValue;
public int intValue;
public test(String str,int i)
{
this.strValue=str;
this.intValue=i;
}
public test()
{
}
public static void main(String argv[]) {
test test1,test2;
test1=new test("Clone test",0);
test2=new test();
try
{
test2=(test)(test1.clone());
}
catch(CloneNotSupportedException e)
{
System.out.println(e.getMessage());
}
System.out.print(test1.strValue+" ");
System.out.println(test1.intValue);
System.out.print(test2.strValue+" ");
System.out.println(test2.intValue);
}
}