This is my first time working with the java interface and im very confused. after reading tutorial online this is what i came up with how to define the interface and implement it but there is red underline on the hours,minutes and seconds. and i cant figure out why its so.
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;
}
}
}
Interfaceare final by default, hence you need to define some value to them, likeint hours = 11, and you will access this field likeMyClock.hourseverywhere else :-)