If I will write
String s=new String("XYZ");
String s1=new String("XYZ");
if(s.equals(s1)){
sop("True");
}
else{
sop("False");
}
This program will give me "True".
But When I am creating my own class suppose
class Employee{
public Employee(String name);
}
Employee e= new Employee("XYZ");
Employee e1 = neew Employee("XYZ");
if(e.equals(e1)){
sop("True");
}
else{
sop("False");
}
Then it will give the output as "False".
Can I know what is happening internally?
Answer Posted / ashish singh
String and other wrapper classes override equals() method of object class. SO when we compare it gives the appropriate result. while the employee class did not do it.
| Is This Answer Correct ? | 10 Yes | 0 No |
Post New Answer View All Answers
What are the types of arrays in java?
Why are variables important in research?
What is set in java?
placement papaers of spring computing technology
How can we find the actual size of an object on the heap?
How many bytes is string in java?
What is a dynamic array java?
List the three steps for creating an object for a class?
Is java jre still free?
What are the 4 types of research methods?
When will you define a method as static in Java?
What is an interoperable application in java ?
What is thread pool in java with example?
When to use runnable interface vs thread class in java?
What is java util list?