-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathParenting.java
More file actions
35 lines (29 loc) · 741 Bytes
/
Parenting.java
File metadata and controls
35 lines (29 loc) · 741 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
interface FlyingCreature {
String getName();
default void fly() {
System.out.println(getName() + " is flying");
}
}
abstract class NamedCreature {
String name;
public NamedCreature(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
class Griffon extends NamedCreature implements FlyingCreature {
public Griffon(String n) { super(n); }
}
class Dragon extends NamedCreature implements FlyingCreature {
public Dragon(String n) { super(n); }
}
public class Parenting {
public static void main(String ... args) {
Dragon d = new Dragon("Smaug");
Griffon g = new Griffon("Gilda");
d.fly(); // Smaug is flying
g.fly(); // Gilda is flying
}
}