File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes question 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" Watch "question" New topic
Author

question

xin sun
Greenhorn

Joined: Feb 02, 2005
Posts: 1
QUESTION NO: 104
Given that b and c refer to instances of wrapper classes, which two statements are
true? (Choose two)
A. b.equals(b) returns true.
B. b.equals(c) returns the same result as b == c.
C. b.eqials(c) can return false even if c.equals(b) returns true.
D. b.equals(c) throws an exception if b and c are different wrapper types.
E. b.equals(c) returns false if the type of wrapper objects being compared are different.

Answer: B, C

why? thanks!


(No need to shout, and please use a meaningful topic)
[ February 20, 2005: Message edited by: Barry Gaunt ]
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

If you experiment with some code, you'll quickly see that the answers provided are not correct.

For example, A is true and B is false. (Well, actually B is true if you're using 1.5 to autobox a value within the range of a byte, but I don't think that's what they're asking.)


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Joyce Lee
Ranch Hand

Joined: Jul 11, 2003
Posts: 1392
Hi Xin Sun,

Statement A and E are correct based on jdk 1.4.

B is incorrect because if b and c are referencing to different objects of the same type and they contain the same value, b.equals(c) returns true.


C is incorrect because there is no such method eqials in any wrapper class.

D is incorrect because it returns false (not throwing an exception) if b and c are different wrapper types (as stated in statement E).


Joyce
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
C is incorrect because there is no such method eqials in any wrapper class.

Even with equals() spelled correctly, c is false because the contract for equals requires:
for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.


[ February 19, 2005: Message edited by: Mike Gershman ]
[ February 20, 2005: Message edited by: Mike Gershman ]

Mike Gershman
SCJP 1.4, SCWCD in process
Joyce Lee
Ranch Hand

Joined: Jul 11, 2003
Posts: 1392
Oops. When spotted "eqials", I thought that's a trick question so I didn't bother to read the rest of the sentence. Thanks for pointing that out, Mike.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: question
 
Similar Threads
equals() for wrapper classes
equals()
Wrapper class question ?
About equals
Equals doubt