forked from bejeyon/KOSA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChap10_ExerciseQ12.java
More file actions
67 lines (54 loc) · 1.18 KB
/
Chap10_ExerciseQ12.java
File metadata and controls
67 lines (54 loc) · 1.18 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
/*
HWJava16_08_Chap10_Exercise_배재연.zip
10장 연습문제
Q11. 다음과 같은 클래스 A가 있다.
class A {
int data;
A(int data) {
this.data = data;
}
}
다음 코드의 실행 결과로 false가 출력되는 이유를 설명하시오.
A a1 = new A(3);
A a2 = new A(3);
System.out.println(a1.equals(a2)); // false
==================================================
Q12. Q11에서 출력값이 true가 나오도록 클래스 A를 수정하시오.
class A {
int data;
A(int data) {
this.data = data;
}
__________________________________________________
}
A a1 = new A(3);
A a2 = new A(3);
System.out.println(a1.equals(a2)); // true
*/
package classes;
class A {
int data;
A(int data) {
this.data = data;
}
@Override
public boolean equals(Object obj) {
if (this.data == ((A)obj).data)
return true;
else
return false;
}
}
class Chap10_ExerciseQ12 {
public static void main(String[] args) {
A a1 = new A(3);
A a2 = new A(3);
System.out.println(a1.equals(a2)); // true
/*
String str1 = new String("안녕");
String str2 = new String("안녕");
System.out.println(str1==str2); // false
System.out.println(str1.equals(str2)); // true
*/
}
}