+ 1

What's meaning of two objects are same ?? Give some examples..

20th Jul 2018, 3:00 PM
Amit Yadav
Amit Yadav - avatar
6 Answers
+ 2
class A {} A obj = new A(); A obj2 = obj; System.out.print(obj==obj2);
20th Jul 2018, 3:09 PM
Hatsy Rei
Hatsy Rei - avatar
+ 2
No. You created different objects dynamically using the new keyword.
20th Jul 2018, 3:12 PM
Hatsy Rei
Hatsy Rei - avatar
+ 1
A obj = new A("Amit"); A obj1 = newA("Amit"); are they same object??
20th Jul 2018, 3:11 PM
Amit Yadav
Amit Yadav - avatar
+ 1
Integer a= new Integer(10); Integer b= a; Integer c= b; Here a b and c are differents variables that point to same object
20th Jul 2018, 3:12 PM
KrOW
KrOW - avatar
+ 1
if they are not same then they should generate different HashCode .. and if they going to generate different HashCode how we going to compare equality using equals..
20th Jul 2018, 3:14 PM
Amit Yadav
Amit Yadav - avatar
+ 1
same objects its different from equals objects
20th Jul 2018, 3:15 PM
KrOW
KrOW - avatar