-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathObjectPassDemo.java
More file actions
44 lines (39 loc) · 999 Bytes
/
ObjectPassDemo.java
File metadata and controls
44 lines (39 loc) · 999 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
// Java Program to Demonstrate Objects Passing to Methods.
// Class
// Helper class
class ObjectPassDemo {
int a, b;
// Constructor
ObjectPassDemo(int i, int j)
{
a = i;
b = j;
}
// Method
boolean equalTo(ObjectPassDemo o)
{
// Returns true if o is equal to the invoking
// object notice an object is passed as an
// argument to method
return (o.a == a && o.b == b);
}
}
// Main class
public class GFG {
// MAin driver method
public static void main(String args[])
{
// Creating object of above class inside main()
ObjectPassDemo ob1 = new ObjectPassDemo(100, 22);
ObjectPassDemo ob2 = new ObjectPassDemo(100, 22);
ObjectPassDemo ob3 = new ObjectPassDemo(-1, -1);
// Checking whether object are equal as custom
// values
// above passed and printing corresponding boolean
// value
System.out.println("ob1 == ob2: "
+ ob1.equalTo(ob2));
System.out.println("ob1 == ob3: "
+ ob1.equalTo(ob3));
}
}