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


why the equals method can be override?when we override the
equals method?

Answers were Sorted based on User's Feedback



why the equals method can be override?when we override the equals method?..

Answer / subhareddy

equals method available in object class is for address
comparison not for content comparison.so for content
comparison we have to override equals method in our class.
wrapper classes and string class has overridden equals
method for content comparison.

Is This Answer Correct ?    11 Yes 3 No

why the equals method can be override?when we override the equals method?..

Answer / dsureshkumar28

question is not clear
may ur question is
why hashcode() will be override when u override equals()?
is it

Is This Answer Correct ?    5 Yes 1 No

why the equals method can be override?when we override the equals method?..

Answer / ganesh

We need to override the equals method when we write our own class and we want the instance of that class to be part of some collection.

When you place the object in collection and make the manipulation on them, say sorting/searching etc.
The comparison of the object has to be done by the alogorithm.
The Algorithm uses the equals method to check for equality of two objects. Otherwise it wont be having any means to check for equality.

class Student
{
private String serialNo;
private String name;
}

two student objects with the same name cannot be the same students, but two student objects with the same serial number should the same object.

search(Student st,List a)
{
Collections.binarySearch(a,st);

}

when you want to put the objects in the hashMap, then overriding the cashCode is necessary. HashMap calls the hashCode method on the object to insert into HashMap.

Is This Answer Correct ?    4 Yes 0 No

why the equals method can be override?when we override the equals method?..

Answer / madhu

equals() method will be available in primodian class that is
Object class, but by default it compares only the addresses,
not the contents, So if you want the content comparison you
have to override equals(), but if u override the equals(),
you have to override the hashCode() also.

Is This Answer Correct ?    3 Yes 2 No

why the equals method can be override?when we override the equals method?..

Answer / manju kt

to check if 2 objects references to the same memory
location..

Is This Answer Correct ?    1 Yes 9 No

Post New Answer

More Core Java Interview Questions

Is 'sizeof' a keyword?

7 Answers  


. Differentiate between instance and local variables.

1 Answers  


What are the access modifiers available in java?

0 Answers  


What are the two types of java?

0 Answers  


If you do not want your class to be inherited by any other class. What would you do?

0 Answers  


What if I write static public void instead of public static void in java?

0 Answers   Winsol Solutions,


10. class Nav{ 11. public enum Direction { NORTH, SOUTH, EAST, WEST } 12. } 13. public class Sprite{ 14. // insert code here 15. } Which code, inserted at line 14, allows the Sprite class to compile? a)Direction d = NORTH; b)Nav.Direction d = NORTH; c)Direction d = Direction.NORTH; d)Nav.Direction d = Nav.Direction.NORTH;

2 Answers  


what is the final keyword denotes in java?

0 Answers   IBS,


what is deadlock in threads? with example

2 Answers   CTS, XOXO,


What is unmodifiable collection in java?

0 Answers  


Can we serialize singleton class?

0 Answers  


give an example for encapsulation?

0 Answers   Aspire,


Categories