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 is bom encoding?
Can we instantiate interface in java?
Is main a function?
Is class is a data type?
what is ststic with example
Which command from the jdk compiles a java program?
What is an abstract class and what is it’s purpose?
What is a qualifier in a sentence?
What is java Applet?
Is alive method in java?
Explain about interrupt() method of thread class ?
What is abstraction in java?
What is JDBC Driver interface?How can you retrieve data from the ResultSet
What is type inference in java8?
What is rmi and steps involved in developing an rmi object?