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

Which command from the jdk compiles a java program?

999


When should I use singleton pattern?

1034


Can we use catch statement for checked exceptions when there is no chance of raising exception in our code?

1037


Can two objects have same hashcode?

1005


Explain the importance of thread scheduler in java?

1018


Can java list contain duplicates?

1021


What is the instance of an object?

1196


How do you find the maximum number from an array without comparing and sorting?

1123


What technique is carried out to find out if a particular string is empty?

1017


how to deploy tomcatserver to weblogic server? write d following steps?

1968


Considering notepad/ie or any other thing as process, what will happen if you start notepad or ie 3 times? Where 3 processes are started or 3 threads are started?

1156


How do you reverse a string in java without using string buffer?

1104


Why are variables important in research?

946


What is stack example?

1031


Can we define private and protected modifiers for the members in interfaces?

1105