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
How do you remove all elements from an arraylist in java?
What does main method?
What is mnemonic in assembly language?
Describe the Big-O Notation.
What is the purpose of the finalize() method?
Is void a return type?
What is the difference between delete and delete[]
What is the static field modifier?
What modifiers may be used with an inner class that is a member of an outer class in java programming?
What is the difference between Grid and Gridbaglayout?
Why is java so important?
What is java objectoutputstream?
Which package has light weight components?
What is a singleton factory?
What is the largest long allowed by java?