Skip to content

Instantly share code, notes, and snippets.

@einnar82
Created January 28, 2020 06:59
Show Gist options
  • Save einnar82/f5caefd209978a4948cb335e380adf18 to your computer and use it in GitHub Desktop.
Save einnar82/f5caefd209978a4948cb335e380adf18 to your computer and use it in GitHub Desktop.
Superclass vs Subclass part 2
public class MountainBike extends Bicycle {
// Now, the Bicycle class is the SUPERCLASS and the MountainBike class is the SUBCLASS
// the MountainBike subclass adds one field
public int seatHeight;
// the MountainBike subclass has one constructor
public MountainBike(int startHeight,
int startCadence,
int startSpeed,
int startGear) {
super(startCadence, startSpeed, startGear);
seatHeight = startHeight;
}
// the MountainBike subclass adds one method
public void setHeight(int newValue) {
seatHeight = newValue;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment