请Tompage给一个示例, 谢谢:)

解决方案 »

  1.   

    是不是要这样的东西:
    public class InnerTest{ 
      public static void main(String args[]){ 
        a x = new a(10);
        x.print();
        a c = new a(x);
        c.print();
       } 
     } 
     class a{
      private int i;
      a(int i){
        this.i = i;
       }
      a(a demo){
        i = demo.i;
      }
      public void print(){
       System.out.println(i);
      }
    }
      

  2.   

    clone方法对应于c++中的拷贝构造函数
      

  3.   

    请问hello_wyq(半瓶墨水) 
    我所见过的 clone 方法都是显式调用的,而且需要放在try块中,怎么会和c++中的拷贝构造函数一样呢?java中一个class也能写成
    public class a{
        public a(a b){
        }
    }
    这样的构造函数,和c++的拷贝构造函数差不多吧,这样的构造函数一样可以完成clone方法所完成的功能,
    不太明白clone方法的特别之处,谁能解释一下?