Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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 / vikas

Extending Ashish Singh's answer, If you want employee to return true for the use case you have mentioned, override your equals and hashcode method and check only for the String object that you have in employee class in your overridden equals method. It'll return true.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Give me some null interfaces in java?

1006


What is the difference between access specifiers and access modifiers in java? 16

953


What do you understand by the term wrapper classes?

941


What are methods of a class?

974


Write a program to reverse a number in java?

1039


Why can we not override static method?

1063


Can an interface implement another interface?

975


How to declare an arraylist in java?

997


How does multithreading take place on a computer with a single cpu?

949


what is the role of xml in core java?? and how we can use it?? can somebody give a sample program with explanation and from where i can read more about xml?????

2192


Can the interface be final?

961


What is an image buffer?

923


How to pass arraylist to stored procedure in java?

1058


Can we declare a class as abstract without having any abstract method?

948


what is meant by abstract class?

1059