Skip to content

Instantly share code, notes, and snippets.

@peterkos
Last active November 12, 2017 22:15
Show Gist options
  • Save peterkos/96e9bb3b1459d63ae004dc45767d4bf3 to your computer and use it in GitHub Desktop.
Save peterkos/96e9bb3b1459d63ae004dc45767d4bf3 to your computer and use it in GitHub Desktop.
Changed title.
// Created by @peterkos
// Ported from Swift, originally by Apple
import java.util.*;
public class InheritingInheritance {
public static void main(String[] args) {
Car car = new Car("red");
RaceCar raceCar = new RaceCar("blue", true);
}
}
class Car {
private String paintColor;
public void fillGasTank() {
System.out.println("Filled gas tank");
}
public Car(String paintColor) {
this.paintColor = paintColor;
fillGasTank();
}
}
class RaceCar extends Car {
private boolean hasTurbo;
public void fillGasTank() {
System.out.println("Filled gas tank quickly");
System.out.println(hasTurbo);
}
public RaceCar(String paintColor, boolean hasTurbo) {
super(paintColor);
this.hasTurbo = hasTurbo;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment