OnJava8-Examples/interfaces/HorrorShow.java

55 lines
1022 B
Java
Raw Normal View History

2015-04-20 15:36:01 -07:00
//: interfaces/HorrorShow.java
// Extending an interface with inheritance.
interface Monster {
void menace();
}
interface DangerousMonster extends Monster {
void destroy();
}
interface Lethal {
void kill();
}
class DragonZilla implements DangerousMonster {
2015-05-05 11:20:13 -07:00
@Override
2015-04-20 15:36:01 -07:00
public void menace() {}
2015-05-05 11:20:13 -07:00
@Override
2015-04-20 15:36:01 -07:00
public void destroy() {}
2015-05-18 23:05:20 -07:00
}
2015-04-20 15:36:01 -07:00
interface Vampire extends DangerousMonster, Lethal {
void drinkBlood();
}
class VeryBadVampire implements Vampire {
2015-05-05 11:20:13 -07:00
@Override
2015-04-20 15:36:01 -07:00
public void menace() {}
2015-05-05 11:20:13 -07:00
@Override
2015-04-20 15:36:01 -07:00
public void destroy() {}
2015-05-05 11:20:13 -07:00
@Override
2015-04-20 15:36:01 -07:00
public void kill() {}
2015-05-05 11:20:13 -07:00
@Override
2015-04-20 15:36:01 -07:00
public void drinkBlood() {}
2015-05-18 23:05:20 -07:00
}
2015-04-20 15:36:01 -07:00
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);
}
} ///:~