{
return creator; }
// Setter method for creator
public void setCreator(Name name) {
creator = name; }
// Override the protected clone method defined in the Object class public Object clone() {
Object o=null; try {
o=(CloneableCircle)super.clone(); }
catch (CloneNotSupportedException ex) {
return null; }
// ((CloneableCircle)o).creator=(Name)creator.clone(); return o; }
// Override the toString method defined in the Object class public String toString() {
return super.toString() + \ } }
class Name implements Cloneable { private String firstName; private String middlName; private String lastName; public Name(String f,String m,String l) { firstName=f; middlName=m; lastName=l;
} public String getFullname() { String s=firstName+\ return s; } public void setFirstname(String s) { firstName=s; } public void setMi(String s) { middlName=s; } public void setLastName(String s) { lastName=s; }
public Object clone() {
Object o=null; try {
o=(Name)super.clone(); }
catch (CloneNotSupportedException ex) {
return null; }
return o; } }
16、16、将上面编辑的源程序保存成Java源程序文件(扩展名为java),程序
文件名分别为、Circle.java、TestCloneable.java。
a) 进入命令提示符状态,在源程序文件存放目录下分别编译以上源程
序文件。观察编译后源程序文件存放目录中的文件,熟悉Java程序的文件结构。
b) 如果编译正确,则键入如下命令行,使用Java解释器运行源程序: java TestCloneable
程序运行结果如下:
四、实验难点:
多态性的实现和对象内容的复制是本次实验的难点,同学们要重点理解。