【文件属性】:
文件名称:clone方法示例-Chap6 Java常用类
文件大小:330KB
文件格式:PPT
更新时间:2021-04-26 09:28:02
java常用类
clone方法示例
public class TestClone {
public static void main(String[] args) {
Teacher t1 = new Teacher("Li", 30);
Teacher t2 = t1;
Teacher t3 = (Teacher) t1.clone();
}
}
class Teacher implements Cloneable {
String name; int age;
public Teacher(String name, int age) { this.name = name; this.age = age;}
public Object clone() {
try {
return super.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
return null;
}
}
}