Skip to content

Instantly share code, notes, and snippets.

@kahneraja
Last active January 5, 2018 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kahneraja/4199a2ccb621a7e15842a4d64a9d4f38 to your computer and use it in GitHub Desktop.
Save kahneraja/4199a2ccb621a7e15842a4d64a9d4f38 to your computer and use it in GitHub Desktop.
Exploring Super Interfaces in Java 8.
/* 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