-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathFriendMain.java
More file actions
55 lines (32 loc) · 788 Bytes
/
FriendMain.java
File metadata and controls
55 lines (32 loc) · 788 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package ex;
public class FriendMain {
public static void main(String[] args) {
Friend f1 = new Friend("손흥민");
Friend f2 = new Friend("이강인");
Friend f3 = new Friend("손흥민");
System.out.println(f1); // f1.toString()
System.out.println(f2);
System.out.println(f3);
System.out.println(f1 == f3);
System.out.println(f1.equals(f3));
}
}
class Friend {
String myName;
Friend(String name){
myName = name;
}
public String toString() {
return "나의 이름은 " + myName + "입니다.";
}
public boolean equals(Object o) {
boolean result = false;
if(o != null && o instanceof Friend) {
Friend f = (Friend) o;
if(myName.equals(f.myName)) {
result = true;
}
}
return result;
}
}