clone()是protected函数,不能这样调用

解决方案 »

  1.   

    class testSon implements Cloneable
    {
        public int intSon = 2;
        
        public Object clone() throws CloneNotSupportedException
        {
         return super.clone();
        }
    }
    public class test
    {
        public static void main(String[] args)
        {
             try
             {
             testSon aSon = new testSon();
             testSon bSon = (testSon)aSon.clone();
             System.out.println(bSon.intSon);
            }
            catch(Exception e)
            {
            }
        }
    }
      

  2.   

    To  bobokong(轨迹球) 为什么要这样做呢?能简单解释一下吗?
    谢谢!