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


Please Help Members By Posting Answers For Below Questions

What is polymorphism in java? What are the kinds of polymorphism?

574


Is arraylist ordered in java?

570


What is the exact difference in between Unicast and Multicast object? Where will it be used?

580


How are observer and observable used in java programming?

541


What is parsing in java?

527






What does singleton class mean?

533


Explain about sets?

565


Is string serializable in java?

538


What will be the initial value of an object reference which is defined as an instance variable?

629


What is a boolean used for?

586


What is object english?

581


What is the final keyword?

549


What is the purpose of sizeof operator?

526


Can a class have multiple constructors?

531


What is the difference between math floor and math round?

499