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 Wrapper class question ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Wrapper class question ?" Watch "Wrapper class question ?" New topic
Author

Wrapper class question ?

Sim Kim
Ranch Hand

Joined: Aug 06, 2004
Posts: 268
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.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

A, E is the answer. Hope that I have got it this time . :roll:
[missed A for the first time ]
[ January 12, 2005: Message edited by: Pradeep Bhat ]

Groovy
Zak Guesmia
Greenhorn

Joined: May 28, 2004
Posts: 21
A,E


SCJP1.4, SCWCD1.4, SCBCD1.3, SCDJWS, SCEA(part1), MCP, MCAD.NET, SCJP 5.0 (beta)
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

B is not correct. Wrapper classes do override equals methods. StringBuffer,StringBuilder doesn't.
Vivek Mongolu
Ranch Hand

Joined: Apr 17, 2003
Posts: 42
Wrapper classes override equals() method and return true if both the primitive values and the wrapper's classes are same.

page 384 of K&B book

so I guess teh answer is A and E.
Andris Jekabsons
Ranch Hand

Joined: Jan 20, 2004
Posts: 82
Originally posted by rathi ji:
equals() method is only overridden in String class otherwise it is same as equally operator ( == )[ January 12, 2005: Message edited by: rathi ji ]

Check, for instance, equals() in Integer.
As I've noticed in other posts, I think you should brush up on the difference between "==" and "equals()". The first is used when referring to the same object in the memory by two references, the second when two different objects (occupying different memory locations) have equal values.
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
For another interesting problem, change "equals(X)" to "compareTo(X)==0"


Mike Gershman
SCJP 1.4, SCWCD in process
 
 
subject: Wrapper class question ?