public class Test public static void main String args throws ClassNotS

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
public class Test {
public static void main(String[] args) throws ClassNotSupportedException {
Person h = new Person();
h.name = "Tom";
Person h2 = (Person)h.clone();
}
}
class Person imploment Cloneable {
String name = "";
public boolean equals(Object ob) {
if(ob == null) return false;
if (ob == this) return true;
if (!(ob instanceof Person)) return false;
return this.name.equals(((Person)ob)).name;
}
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
}