59 lines
1.2 KiB
Java
59 lines
1.2 KiB
Java
// interfaces/HorrorShow.java
|
|
// ©2016 MindView LLC: see Copyright.txt
|
|
// We make no guarantees that this code is fit for any purpose.
|
|
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
|
// Extending an interface with inheritance.
|
|
|
|
interface Monster {
|
|
void menace();
|
|
}
|
|
|
|
interface DangerousMonster extends Monster {
|
|
void destroy();
|
|
}
|
|
|
|
interface Lethal {
|
|
void kill();
|
|
}
|
|
|
|
class DragonZilla implements DangerousMonster {
|
|
@Override
|
|
public void menace() {}
|
|
@Override
|
|
public void destroy() {}
|
|
}
|
|
|
|
interface Vampire extends DangerousMonster, Lethal {
|
|
void drinkBlood();
|
|
}
|
|
|
|
class VeryBadVampire implements Vampire {
|
|
@Override
|
|
public void menace() {}
|
|
@Override
|
|
public void destroy() {}
|
|
@Override
|
|
public void kill() {}
|
|
@Override
|
|
public void drinkBlood() {}
|
|
}
|
|
|
|
public class HorrorShow {
|
|
static void u(Monster b) { b.menace(); }
|
|
static void v(DangerousMonster d) {
|
|
d.menace();
|
|
d.destroy();
|
|
}
|
|
static void w(Lethal l) { l.kill(); }
|
|
public static void main(String[] args) {
|
|
DangerousMonster barney = new DragonZilla();
|
|
u(barney);
|
|
v(barney);
|
|
Vampire vlad = new VeryBadVampire();
|
|
u(vlad);
|
|
v(vlad);
|
|
w(vlad);
|
|
}
|
|
}
|
|
/* Output: (None) */
|