public String getPress() { } public void setPress(String press) { } public String toString() { } public Object clone() throws CloneNotSupportedException { } } return super.clone(); return name+price+author+owner+press; this.press = press; return press; Lili类; public class Lili { public static void main(String[] args) throws } } Book a = new Book(); a.setAuthor(\); a.setName(\程序设计\); a.setOwner(\); a.setPress(\清华大学出版社\); a.setPrice(29.50f); Book b = (Book)a.clone(); b.setOwner(\); System.out.println(a); System.out.println(b); CloneNotSupportedException { 实验总结:通过实验了解了原型模式的结构的优点和缺点。还知道了适用场景。
- 15 -