-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPolymorphismSimple.java
61 lines (44 loc) · 995 Bytes
/
PolymorphismSimple.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package algorithms;
/**
*
* @author Gökhan DAĞTEKİN
*
* 2016
*/
interface Speak {
String getName();
String getMessage();
}
abstract class Human implements Speak {
private final String name;
protected Human(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
}
class Turk extends Human {
public Turk(String name) {
super(name);
}
public String getMessage() {
return "Merhaba";
}
}
class American extends Human {
public American(String name) {
super(name);
}
public String getMessage() {
return "Hello";
}
}
public class PolymorphismSimple {
public static void main(String[] args) {
Human turk = new Turk("Gökhan");
Human american = new American("Micheal");
System.out.println(turk.getName() + " " + turk.getMessage());
System.out.println(american.getName() + " " + american.getMessage());
}
}