what is the difference between equals method and ==
Answer Posted / anilkumar
"==" is used to evaluate whether tht two objects are of same type or not.
Eg: A a1=new A();
A a2=new A();
A a3=a1;
a1==a2 returns false, because a1 reference and a2 reference are not same.
a3==a1 returns true because a3 reference is pointing to a1.
"equals()" compares the contents of objects.
Eg:A a1=new A(10);
A a2=new A(10);
A a4=new A(20);
a1.equals(a2) returns true because both contents are same.
a1.equals(a4) returns false because their contents are different.
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Why singleton is not thread safe?
what are the high-level thread states? : Java thread
What is static keyword in java?
what do you mean by java annotations?
How does a for loop work java?
What is a map in java?
Why is string buffer better than string ?
Can we override private method?
What is the difference between break and continue statements?
What is a method vs function?
What is the purpose of static methods and static variables?
What is null object in java?
How can we create objects if we make the constructor private ?
Explain about anonymous inner classes ?
Why there are some null interface in java? What does it mean?