`

clone 的一个简单例子

 
阅读更多

import java.util.Arrays;


public class maopao implements Cloneable {

 @Override
 protected Object clone() throws CloneNotSupportedException {
  // TODO Auto-generated method stub
   maopao a=null;
          a=(maopao)super.clone();
  return a;
 }

 /**
  * @param args
  */
   String name="beautiful gril";
   int id=80;

 public static void main(String[] args) {
   maopao a=new maopao();
      a.id=90;
         maopao b=null;
   try {
    b = (maopao) a.clone();
   } catch (CloneNotSupportedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
         a.name="so beautiful";
         b.name="she is my girl friend";
         System.out.println("a的id= "+a.id+"b的id= "+b.id);
         System.out.println(a.name+"!          "+b.name);
 }
 }

 

分享到:
评论
发表评论

文章已被作者锁定,不允许评论。

相关推荐

Global site tag (gtag.js) - Google Analytics