• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question 10.2 of khalid mughal's book

 
darshan engineer
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ranchers,
I have a doubt regarding option b and e of q.10.2 of Khalid mughals book. Isnt option B right.

Thanks
 
harish shankarnarayan
Ranch Hand
Posts: 158
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
friend do paste the question or the link to it
 
darshan engineer
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry friends, i forgot to put the question itself. neways here is the question.

Which statement is true?

Select the one correct answer.

A)If the references x and y denote two different objects, then the expression x.equals(y) is always false.

B)If the references x and y denote two different objects, then the expression (x.hashCode() == y.hashCode()) is always false.

c)The hashCode() method in the Object class is declared final.

D)The equals() method in the Object class is declared final.

E)All arrays have a method named clone.

my doubt is that since clone belongs to the object class, all classes will have that method. secondly since hashcode method returns different values for different objects, isnt b also right
 
rey anz
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can override the hascode() method in a class so as to return same value everytime. Then using '==' on two different objects would result in true as they return the same value, so B is not correct.
 
Leonardo Rafaeli
Ranch Hand
Posts: 58
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya but remember the "contract"...
folowing the contract, "if x.equals(y), x.hashCode() must be == y.hashCode()"

anyway

if x.equals(y) == true and the hashCode are differents, it will compile without error and will work correctly BUT is not "cool". if u want, u can override equals to always return "true" or hashCode always return as "666". When u create a object is cool u create your own rules to compare two same objects and returning a correct asnwer, if they are equals or not

crazy question
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic