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


Please Help Members By Posting Answers For Below Questions

how do I create a runnable with inheritance? : Java thread

505


What is the basic difference between string and stringbuffer object?

577


List down the methods and interfaces of collection class in java.

538


Explain the public class modifier?

499


What are the features of java?

529






What is use of functional interface in java 8? Explain

565


Why do we need wrapper class?

535


Is null function in java?

564


What is the difference between compile-time polymorphism and runtime polymorphism?

557


Is the milky way in a void?

538


What is the function of java?

513


What is fundamental datatype?

523


How does arraylist work in java?

527


What are functions in java?

496


Why do we create threads in java?

572