Last active
January 28, 2020 07:02
-
-
Save einnar82/71da81c1dfc4a3db436a742d421b07dc to your computer and use it in GitHub Desktop.
Superclass vs Subclass part 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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