samedi 4 avril 2015

Cannot reduce the visibility of the inherited method from object

I have defined the following two classes:



public abstract class Subject {

private ArrayList<ClockObserver> clockObserverList = new ArrayList<ClockObserver>();


public void attach(ClockObserver clockObserver) {
// begin-user-code
// TODO Auto-generated method stub
clockObserverList.add(clockObserver);
// end-user-code
}
public void dettach(ClockObserver clockObserver) {
// begin-user-code
// TODO Auto-generated method stub
clockObserverList.remove(clockObserver);
// end-user-code
}

protected void notify() {
// begin-user-code
// TODO Auto-generated method stub
for(int i= 0; i < clockObserverList.size(); i++)
{
clockObserverList.get(i).update();
}
// end-user-code
}
}


and



public class SystemClock extends Subject {
private int hour;
private int minute;
private int second;
public void setTime(int hour, int minute, int second) {
this.hour = hour;
this.minute= minute;
this.second = second;
notify();
}
public ClockTime getTime() {
ClockTime clockTime = new ClockTime();
clockTime.hour = this.hour;
clockTime.minute = this.minute;
clockTime.second = this.second;
return clockTime;
}
public void displayTime() {

System.out.println("Time is :" + this.hour + ":" + this.minute + ":" + this.second);
}
}


I got the following error for notify function:



Multiple markers at this line
- Cannot override the final method from Object
- overrides java.lang.Object.notify
- Cannot reduce the visibility of the inherited method from


Even when I change its visibility from protected to public, I still have the following error:



Multiple markers at this line
- Cannot override the final method from Object


Could you please help me what is the problem?


Aucun commentaire:

Enregistrer un commentaire