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 / prachi
Equals() method of Qbject class checks whether reference id's are same or not.if overridden then it will check for the value contained in those reference id's.String class has overridden equals() so it checks for the value whereas Employee class hasn't so Object class' method runs and reference id's are compared.
| Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
Explain about anonymous inner classes ?
What do you mean by mnemonics?
What is the benefit of singleton pattern?
Explain java thread life cycle.
What is flag in java?
What is a text string?
What is treemap in java?
Give an example of use of pointers in java class.
What is a literal coding?
what is the difference between process and thread? : Java thread
hi am an engineering student and my next plan is for ms in either in us or australia i got my passport but i dont know anything bout visa can u give brief idea 1)How to get prepared for visa and 2)How to apply for top universities and 3)How to pay the fee and so on These all are basic questions plz give me a clear idea
Why chararray() is preferred over string to store the password?
How to make a non daemon thread as daemon?
Can you access the private method from outside the class?
How do you allocate memory to object?