-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
64 lines (55 loc) · 1.29 KB
/
Copy pathMain.java
File metadata and controls
64 lines (55 loc) · 1.29 KB
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
62
63
64
package javaExF;
public class Main {
public static void main(String[] args) {
// 서로 다른 객체 생성
Juice j = new Juice();
Coffee c = new Coffee();
Beer b = new Beer();
Water w = new Water();
Tea t = new Tea();
// 부모 클래스 타입의 배열 생성
Drink[] drinks = { j, c, b, w, t };
// 모든 음료를 주문!
for (Drink d : drinks) {
d.ordered();
}
}
}
interface Drink {
public abstract void ordered();
}
class Juice implements Drink {
String name;
double price;
public void ordered() {
System.out.println("주문되었습니다.");
}
}
class Coffee implements Drink {
String name;
double price;
public void ordered() {
System.out.println("주문되었습니다.");
}
}
class Beer implements Drink {
String name;
double price;
public void ordered() {
System.out.println("주문되었습니다.");
}
}
class Water implements Drink {
String name;
double price;
public void ordered() {
System.out.println("주문되었습니다.");
}
}
class Tea implements Drink {
String name;
double price;
public void ordered() {
System.out.println("주문되었습니다.");
}
}