-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathPassOb.java
More file actions
38 lines (27 loc) · 744 Bytes
/
PassOb.java
File metadata and controls
38 lines (27 loc) · 744 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
package chapter7;
//Objects may be passed to methods..
class Test {
int a, b;
Test(int i, int j) {
a = i;
b = j;
}
//Return true if o is equal to the invoking object
boolean equalTo(Test o) {
if (o.a == a && o.b == b) {
return true;
} else {
return false;
}
}
}
public class PassOb {
public static void main(String[] args) {
Test ob1 = new Test(100, 22);
Test ob2 = new Test(100, 22);
Test ob3 = new Test(-1, -1);
System.out.println(" ob1 == ob2 : " + ob1.equalTo(ob2));
System.out.println(" ob1 == ob3 : " + ob1.equalTo(ob3));
System.out.println(" ob2 == ob3 : " + ob2.equalTo(ob3));
}
}