permaculture playing cards*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question 10.2 of khalid mughal's book Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question 10.2 of khalid mughal Watch "Question 10.2 of khalid mughal New topic
Author

Question 10.2 of khalid mughal's book

darshan engineer
Greenhorn

Joined: Nov 22, 2005
Posts: 7
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

Joined: Sep 12, 2005
Posts: 158
friend do paste the question or the link to it


Harish<br />SCJP 1.4 (85%)
darshan engineer
Greenhorn

Joined: Nov 22, 2005
Posts: 7
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

Joined: Nov 10, 2005
Posts: 7
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

Joined: Dec 12, 2005
Posts: 58
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


SCJP 1.4, SCWCD 1.4, SCBCD 5, OCUP, SCEA 5 (I), Oracle SOA Implementation Specialist, IBM Websphere Lombardi 7.1 Fundamentals
Blog: [url]http://www.leozin.com.br/blog[/url]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Question 10.2 of khalid mughal's book