-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVariousFriends.java
More file actions
76 lines (61 loc) · 1.67 KB
/
Copy pathVariousFriends.java
File metadata and controls
76 lines (61 loc) · 1.67 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
65
66
67
68
69
70
71
72
73
74
75
76
package javaExF;
public class VariousFriends {
public static void main(String[] args) {
// 객체 생성
Artist kim = new Artist("뮤지션 김씨");
Architect lee = new Architect("건축가 이씨");
Developer park = new Developer("개발자 박씨");
Lawyer choi = new Lawyer("변호사 최씨");
// 그룹화: 인터페이스 기준
Friend[] friends = {kim, lee, park, choi};
for (Friend f : friends) {
f.dearFriend();
}
}
}
/* 1. 해당 인터페이스를 완성하시오. */
interface Friend {
void dearFriend();
}
/* 2. 아래 모든 클래스를 완성하시오. */
class Artist implements Friend {
String name;
public Artist(String name) {
this.name = name;
}
@Override
// 오버라이딩의 접근제어자는 부모보다 작거나 같다.
public void dearFriend() {
System.out.printf("%s -> 칭구 아이가!\n", this.name);
}
}
class Architect implements Friend {
String name;
public Architect(String name) {
this.name = name;
}
@Override
public void dearFriend() {
System.out.printf("%s -> 칭구 아이가!\n", this.name);
}
}
class Developer implements Friend {
String name;
public Developer(String name) {
this.name = name;
}
@Override
public void dearFriend() {
System.out.printf("%s -> 칭구 아이가!\n", this.name);
}
}
class Lawyer implements Friend {
String name;
public Lawyer(String name) {
this.name = name;
}
@Override
public void dearFriend() {
System.out.printf("%s -> 칭구 아이가!\n", this.name);
}
}