-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPassObjAsParam.java
More file actions
30 lines (24 loc) · 611 Bytes
/
PassObjAsParam.java
File metadata and controls
30 lines (24 loc) · 611 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
package oop;
public class PassObjAsParam {
public static void main(String[] args) {
Student s1 = new Student(1, 50);
Student s2 = new Student(1, 50);
Student s3 = new Student(2, 20);
System.out.println("Object s1 == s2: " + s1.equals(s2));
System.out.println("Object s1 == s3: " + s1.equals(s3));
}
}
class Student {
private int id = 10;
private int rollNo = 30;
public Student(int id, int rollNo) {
this.id = id;
this.rollNo = rollNo;
}
boolean equals(Student o) { // Object as a parameter.
if (this.id == o.id && this.rollNo == o.rollNo) {
return true;
}
return false;
}
}