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
Differentiate storage classes on the basis of their scope?
What do you understand by java virtual machine?
What is difference between array and vector?
What's the base class of all exception classes?
Is an empty arraylist null?
You can create a string object as string str = “abc”; why cant a button object be created as button bt = “abc”;? Explain
Write java program to reverse string without using api?
What is keyword in oop?
List any five features of java?
Hi friends am new to java. I read jar file means collection of java files. For executing struts application what are the necessary jar files. " struts.jar " file contains what. can u explain
What are thread local variables?
Is set ordered in java?
What is the output of the below java program?
What is meant by null and void?
What are the types of exceptions?