给你一个例子
/*
* @(#)Test2.java 1.1 2006-11-7
*
* Copyright 2006 Moloon, Inc. All rights reserved.
* MOLOON PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
package com.create.prototype;
/**
* @author lvyg
* @version 1.1, 2006-11-7
* @since JDK1.5
*/
public class Test2 implements Cloneable {
private String test = "";
public String test() {
return test;
}
public Object clone() {
Object obj = null;
try {
obj = super.clone();
} catch (CloneNotSupportedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return obj;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Test2 test = new Test2();
test.test = "123";
System.out.println("test: " + test.test());
Test2 test2 = (Test2) test.clone();
System.out.println("test2: " + test2.test());
}
}