这是我第一次使用 java 接口,我很困惑。在线阅读教程后,我想到了如何定义接口并实现它,但小时、分钟和秒上有红色下划线。我不知道为什么会这样。
interface myClock {
int hours;
int minutes;
int seconds;
public void clock();
public void clock(int x, int y, int z);
public void setTime(int x, int y, int z);
public void incTimeBySec();
public void incTimeByMins(int x);
public void display12hr();
public void display24hr();
}
class time implements myClock {
public void clock() {
hours = 0;
minutes = 0;
seconds = 0;
}
public void clock(int x, int y, int z) {
hours = x;
minutes = y;
seconds = z;
}
public void setTime(int x, int y, int z) {
hours = x;
minutes = y;
seconds = z;
}
public void incTimeBySec() {
if(seconds+1>60) {
seconds = (seconds+1)-60;
minutes++;
hours++;
} else {
seconds+=1;
}
}
}