Last active
November 12, 2017 22:15
-
-
Save peterkos/96e9bb3b1459d63ae004dc45767d4bf3 to your computer and use it in GitHub Desktop.
Changed title.
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
// 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