Skip to content

Instantly share code, notes, and snippets.

@einnar82
Last active January 28, 2020 07:02
Show Gist options
  • Save einnar82/71da81c1dfc4a3db436a742d421b07dc to your computer and use it in GitHub Desktop.
Save einnar82/71da81c1dfc4a3db436a742d421b07dc to your computer and use it in GitHub Desktop.
Superclass vs Subclass part 1
public class Bicycle {
// the Bicycle class has three fields
public int cadence;
public int gear;
public int speed;
// the Bicycle class has one constructor
public Bicycle(int startCadence, int startSpeed, int startGear) {
gear = startGear;
cadence = startCadence;
speed = startSpeed;
}
// the Bicycle class has four methods
public void setCadence(int newValue) {
cadence = newValue;
}
public void setGear(int newValue) {
gear = newValue;
}
public void applyBrake(int decrement) {
speed -= decrement;
}
public void speedUp(int increment) {
speed += increment;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment