to kamanwu(kaman) 
错误边变为:
test.java:27: clone() has protected access in java.lang.Object
                item2=(String)item1.clone();
                                   ^

解决方案 »

  1.   

    clone()是String类的protected方法。
    如果你要用的话,写一个String的继承类。
      

  2.   

    protected的定义好象是方法所有者类及其子类可以使用,但在这个程序中
    item是String,而它为什么就不能使用String的protected方法呢?可以再解释
    详细些吗?
      

  3.   

    public final class String
    extends ObjectString不能被extend.protected方法再它的子类中能用。但是你的程序不能用。public才可以。
      

  4.   

    public class test implements Cloneable{
    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);
    }
    }