-
Notifications
You must be signed in to change notification settings - Fork 23
/
AbstractExample.java
38 lines (27 loc) · 1020 Bytes
/
AbstractExample.java
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
36
37
38
package ocp.chapter.nine;
interface Fly { }
abstract class Animal {
protected abstract void makeNoise(String a);
}
abstract class Bird extends Animal implements Fly { // This class isn't instantiable
public abstract String getName();
protected void makeNoise(String a) { // The first concrete subclass of Bird and Animal (Stork) will not need to override this method, since it's
// overridden here as a nonabstract method. It could be redeclared here as an abstract method too.
System.out.println(a);
}
public void printName() {
System.out.println(getName());
}
}
class Stork extends Bird {
public String getName() { // Must override the parent's abstract methods, or else the class will not compile (l.12).
return "STORK!";
}
}
public class AbstractExample {
public static void main(String... args) {
Stork stork = new Stork();
stork.printName();
stork.makeNoise("Piu piu");
}
}