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
What environment variables do I need to set on my machine in order to be able to run java programs?
What are the advantages of java over C++?
What is native code?
Explain creating threads by implementing runnable class?
What is java virtual machine? Explain
What is the difference between Error, defect,fault, failure and mistake?
We are seeing so many videos/audios as many web sited. But question is these videos or audios are stored in Databases ( Oracle, Mysql, Sybase,... ) or stored any file directory from there they will give the link for that? Pls explain and give sample code to achieve this one? Thanks, Seenu.
Can we overload run() method in java?
What is port number in java?
What is a parameter used for?
What are the important methods of java exception class?
Can we start a thread twice in java?
What is tcp and udp?
Can a final variable be initialized in constructor?
Why object class is super class for every class in java?