Skip to content

Instantly share code, notes, and snippets.

@0x8801
Created September 24, 2015 22:07
Show Gist options
  • Save 0x8801/9ff4c688b02808b33770 to your computer and use it in GitHub Desktop.
Save 0x8801/9ff4c688b02808b33770 to your computer and use it in GitHub Desktop.
Drive.java Rewritten with an Abstract Class and Methods
public class Drive {
public abstract class GermanVehicles {
private String cost = "high";
protected String speedometer = "kilometers"
public int maxSpeed = 280;
public int currentSpeed;
}
public abstract class Safety extends GermanVehicles {
public void speedWarning(); //abstract
public void activateSpeedGovernor(int speed);
}
public class MercedesBenz extends Safety {
public void speedWarning() {
System.out.println("The Benz is going too fast. Please slow down");
}
public void activateSpeedGovernor(int speed) {
currentSpeed = maxSpeed - speed;
System.out.println("Benz slowed down to " + currentSpeed);
}
}
public static void main(String[] args) {
MercedesBenz S550 = new MercedesBenz();
while(1){
if(currentSpeed==maxSpeed){
S550.speedWarning();
S550.activateSpeedGovernor(50);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment