import java.util.*;
class BookName{
String name;
int number;
}
abstract class Note{
BookName name = new BookName();
abstract public void setName(String value);
abstract public int getNumber();
abstract public void setNumber(int value);
abstract public String getName();
}
class StudentNote extends Note implements Cloneable{
BookName name = new BookName();
int isbn;
public void setName(String value){
name.name = value;
}
public void setNumber(int i){
name.number = i;
}
public int getNumber(){
return name.number;
}
public String getName(){
return name.name;
}
public Object clone() throws CloneNotSupportedException{
StudentNote st = new StudentNote();
st = (StudentNote)super.clone();
st.name = new BookName();
st.name.name = name.name;
st.name.number = name.number;
return st;
}
public void setIsbn(int i){
isbn = i;
}
public int getIsbn(){return isbn;}
}
class Manager{
private Vector v = new Vector();
public void add(Note note){
v.addElement(note);
}
public Note get(int i){
return (Note)v.get(i);
}
public int size(){
return v.size();
}
}
class Client{
private StudentNote student;
private static Manager client = new Manager();
public void register()throws CloneNotSupportedException{
student = new StudentNote();
StudentNote st = (StudentNote)student.clone();
client.add(st);
}
public static Manager getInstance(){
return client;
}
}
class test{
public static void main(String[] args)throws CloneNotSupportedException {
Client c = new Client();
c.register();
c.register();
Manager manager = c.getInstance();
StudentNote student = (StudentNote)manager.get(0);
StudentNote st = (StudentNote)manager.get(1);
student.setName("sky");
student.setNumber(101);
student.setIsbn(10001);
st.setName("fly");
st.setNumber(102);
st.setIsbn(10002);
System.out.println(student.getName() + "\t" + student.getNumber() + "\t" + student.getIsbn());
System.out.println(st.getName() + "\t" + st.getNumber() + "\t" + st.getIsbn());
}
}
posted on 2005-08-09 13:03
sky 阅读(206)
评论(0) 编辑 收藏