Computer Science, asked by sasarita7493, 1 year ago

Which statements are true about comparing two instances of the same class, given that the equals() and hashcode() methods have been properly overridden?


a. if the equals() method returns true, the hashcode() comparison == might return false.


b. if the equals() method returns false, the hashcode() comparison == might return true.


c. if the hashcode() comparison == returns true, the equals() method must return true.


d. if the hashcode() comparison == returns true, the equals() method might return true.


e. if the hashcode() comparison != returns true, the equals() method might return true?

Answers

Answered by mohit0404
1

a & d................

Answered by qwcricket10
1

Q) Which statements are true about comparing two instances of the same class, given that the equals() and hashcode() methods have been properly overridden.

1. If the equals() method returns true, the hashcode()comparison==must return false.

2.If the equals() method returns false, the hashcode() comparison!= must return true.

3. If the hashcode() comparison == returns true, the equals() method must return true.

4. If the hashcode() comparison ==returns true, the equals () method returns true.

a) 1 & 4.

b) 2 & 3.

c) 3 & 4.

d) 1 & 3.

Option  (a) 1 and a are the true statements about comparing two instances of the same class.

  • In a class variety of data types of objects can be grouped together.
  • Each member i.e. the objects are denoted by the term instance.
  • In the case of comparing two values, the using method is the equals()method.
  • To find a hashcode for an object of integer type given, the hashcode() method is used.
  • Here, the 1^{st} and 4^{th} are true about the process of comparing two instances of a class.

#SPJ2

Similar questions