Hey lads, I have a small problem re inheritance. The 1st piece of code is the superclass which contains hour and minute. The 2nd piece of code which is the subclass, contains the int second. The 2nd piece inherits the code from the 1st piece. Now when seconds go over 59, seconds returns to zero and 1 would be added to the minute in superclass. My problem is that i'm not sure how to change the value of the private int minute from a subclass if that makes sense. I highlighted below what my problem is.
public class CurrentTime{
private int hour;
private int minute;
public void advance(CurrentTime timeToAdvance)
{
this.hour = this.hour + timeToAdvance.getHour();
this.minute = this.minute + timeToAdvance.getMinute();
if(this.minute > 59){
this.minute = this.minute - 60;
hour++;
}
if(this.hour > 23){
this.hour = this.hour - 24;
}
}
}
public class FullTime extends CurrentTime {
private int seconds;
public void advance(FullTime timeToAdvance)
{
super.advance(timeToAdvance);
this.seconds = this.seconds + timeToAdvance.getSeconds();
if(this.seconds > 59){
this.seconds = this.seconds - 60;
[B]super.b++;[/B]
}
}
}
So basically, i'm trying to call the int b (which is the int minute) from the superclass and add one to it once seconds go over 59(which is in subclass). I've put in super.b but it's obviously wrong. Does anybody have any ideas?