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...


How to override a equals() method and what is the use?



How to override a equals() method and what is the use?..

Answer / rohan

equals is a method in Object class..
By default in java all the classes extend object class so
any two object can be compared using the equals method...

Provided user implement their own equals method(Override),
because the original equals method compares two objects by
their reference..

If you have a class

class A
{
int value;
p s v m(String args[]){
A obj1= new A();
abj1.value = 10;
A obj2= new A();
abj2.value = 10;

// now if try to compare these two classes

sop(obj1.equals(obj2)) // Result will be always false
} //unless you override
the equals method

boolean equals(A a){
if (a.value == this.value)
return true;
else
return false;
}//Placing this method in the above class will override
the equals method and you will be able to compare
actually the properties of those two object not
their references.

Is This Answer Correct ?    7 Yes 0 No

Post New Answer

More Core Java Interview Questions

Why does my function print none?

0 Answers  


What are command line arguments?

5 Answers  


What does singleton class mean?

0 Answers  


What advantage does an entity bean have over a sessin bean?

3 Answers   Adobe,


what is the JNDI?

3 Answers  


What happens if we override only equals?

0 Answers  


explain the life cycle of thread?

10 Answers   CTS, NIIT, TCS,


What is the purpose of default constructor?

0 Answers  


If you are given the name of the function at run time how will you invoke the function?

0 Answers   Adobe, Yahoo,


Explain implementation and how is it different from conversion?

0 Answers   Aricent,


What are the string methods in java?

0 Answers  


Write a program to search a number in the given list of numbers.

0 Answers   Honeywell,


Categories