Last active
January 5, 2018 14:40
-
-
Save kahneraja/4199a2ccb621a7e15842a4d64a9d4f38 to your computer and use it in GitHub Desktop.
Exploring Super Interfaces in Java 8.
This file contains 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
/* INTERFACES */ | |
interface Plane { | |
default void drive() { | |
System.out.println("We are driving a plane!"); | |
} | |
} | |
interface Boat extends Vehicle { | |
@Override | |
default void drive() { | |
System.out.println("We are driving a boat!"); | |
} | |
} | |
interface Vehicle { | |
default void drive() { | |
System.out.println("Everything is driveable..."); | |
} | |
} | |
/* CLASSES */ | |
class Seaplan implements Plane, Boat { | |
@Override | |
public void drive() { | |
// System.out.println("Woo! Let's drive!"); | |
Plane.super.drive(); // #DiamondInheritance. Specify the chosen interface. | |
} | |
} | |
class Bicycle implements Vehicle { | |
// takes default drive() implementation provided in the interface. | |
} | |
class Main { | |
public static void Main() { | |
Seaplan s = new Seaplan(); | |
s.drive(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment