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

in the first case equals method compares the sequence of characters pointed by s and s1. as both are same it returns true. in the second case it is comparing the references i.e addresses of objects e and e1. as both are not same, it returns false.

Is This Answer Correct ?    11 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Convert Binary tree to linked list.

1084


What is nullpointerexception in java?

1144


What are the advantages and disadvantages of reference counting in garbage collection?

1022


Which is the best sorting technique in java?

978


Is java hashset ordered?

1106


What are the different data types in java?

999


What is a function argument in java?

990


Does java support multiple inheritance or not?

1095


Explain the importance of finalize() method.

964


What modifiers may be used with an inner class that is a member of an outer class in java programming?

1096


What is the file extension for java?

1069


Who is the owner of java?

997


What does arrays sort do in java?

1015


What is class variable java?

1006


Does java set allow duplicates?

1075