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 / k.packiya lakshmi
In String we can write a string in double quotes and equals is
one method of string but when we creating class it doesn't
know the method of equals.
| Is This Answer Correct ? | 3 Yes | 3 No |
Post New Answer View All Answers
How to perform linear search in java?
What is a substitution variable?
Assume a thread has lock on it, calling sleep() method on that thread will release the lock?
What is == in java?
What is a final class in java?
Can you sort a list in java?
Can we declare an interface as final?
What is comparable and comparator interface? List their differences
Why are getters and setters used?
What is "this" keyword in java? Explain
What is difference between string and stringbuffer?
How do you reverse a string in java without using string buffer?
What is an exception in java?
Can I uninstall java?
Which sorting algorithm is in place?