Ebay Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
1
of 1 vote

hashcode() is mainly used for defining hash function as equals() is called only when collision occurs. So, having a good hashfunction will save you time by not calling equals()

- Messi February 17, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Very right .... Thanks ... another one of the same types could be why do we need to override the hashcode function if we override the equals method for object class.

- @ SB February 17, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

as explained by SB hasCode() is used for the hashing function, so lesser the time while searching some element.
When an object is checked for equality first hasCode value is checked and if it is not equal then only equals method is called.
Consider a situation when you have not overridden hasdcode() method.

Employee e1 : name= "abc"
Employee e2: name= "abc"
Both are logically equal, so hashCode() should return the same value as per the hashCode and equals method contract.

If you do not override the hashCode method, then it will return 2 different value when 2 objects are compared.
And even if above object are equal, it will return false.

- Piyush March 16, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

THANKS

- anshulzunke September 12, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

hashcode defines the has fucntion. equals is called when there is a collision in the hash function

- naresh.murali August 08, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1) If two objects are equal, then they must have the same hash code.
2) If two objects have the same hash code, they may or may not be equal.

- purva7 December 10, 2019 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More