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


Please Help Members By Posting Answers For Below Questions

Is it possible to instantiate the abstract class?

544


Is minecraft 1.15 out?

559


What class allows you to read objects directly from a stream in java programming?

518


What is the syntax and characteristics of a lambda expression? Explain

551


What does flagged out mean?

576






What about main thread in java?

656


What is int short for?

527


What is regex java?

567


What is string value?

646


Which collection is sorted in java?

556


What is the final access modifier in java?

621


What are the major drawbacks of external iteration?

580


Is void a type?

594


What is passing parameters in java?

531


Is it safe to install java on my computer?

550