import java.util.Observable;
public class Boy extends Observable{
private String name;
public Boy(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void endOfLearning(){
System.out.println("学习结束");
//标记当前这个 Observable 对象已经被改变了,hasChanged 方法将返回 true
this.setChanged();
//如果当前对象被改变了,那么通知它所有的观察者,然后调用 clearChanged 方法标记此对象
this.notifyObservers(); //等价于 notifyObservers(null)
}
}
public class Boy extends Observable{
private String name;
public Boy(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void endOfLearning(){
System.out.println("学习结束");
//标记当前这个 Observable 对象已经被改变了,hasChanged 方法将返回 true
this.setChanged();
//如果当前对象被改变了,那么通知它所有的观察者,然后调用 clearChanged 方法标记此对象
this.notifyObservers(); //等价于 notifyObservers(null)
}
}