wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes K&B book, page 503 q9 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "K&B book, page 503 q9" Watch "K&B book, page 503 q9" New topic
Author

K&B book, page 503 q9

Keith Nagle
Ranch Hand

Joined: May 06, 2008
Posts: 65
Hi all.
I took a stab at question 9 on page 503 of K&B SCJP 5
book. I guessed incorrectly and noticed that
one of the correct answers is G.
I dont really understand what is happening here.
I would have imagined that the Integer object would be unboxed
to an int...
Can someone be so kind as to elaborate on why G. is a correct answer?
Thank you & regards.


SCJP 5.0
Noam Wolf
Ranch Hand

Joined: Jan 12, 2008
Posts: 35
Hi Keith, can you please provide the question and possible answers? I don't have a copy of the book handy.


because .net guys can also write in java
Antonio Tercero
Ranch Hand

Joined: Jun 05, 2008
Posts: 110
G is correct because when you pass new Long("123"), System.out.format evaluates new Long("123").toString()

Remember:
%s
if argument is null, result is null.
if argument is a primitive type , result=primitive
if argument is a string, result=string
if argument is an object, result=object.toString().


SCJP 5, SCWCD 5
Keith Nagle
Ranch Hand

Joined: May 06, 2008
Posts: 65
Thanks for that concise answer Antonio.
Much appreciated.

Originally posted by Noam Wolf:
Hi Keith, can you please provide the question and possible answers? I don't have a copy of the book handy.


Sorry Noam, but Im not going to post copyrighted material
in the forums. If you haven't already bought the book,
you should, if you can. Check out Amazon. It's a great book
and would definitely benefit you in your studies.
best regards & good luck.
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8801
    
    5
Hi Guys,

The general policy at the ranch is that it's okay to post mock exam questions as long as you cite the source of the question. So in this case it would have been fine to say: "Here's a question from K&B..."

It's also fine to quote small sections from books. I'd say that most authors are really happy if you're discussing their books, as long as you got your copy legally

hth,

Bert


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Keith Nagle
Ranch Hand

Joined: May 06, 2008
Posts: 65
Duly noted Bert.
Thanks for a great publication and keep up the good work!
best regards.
K

Here's the pertinent question Noam,
from the K&B SCJP 5 book:
Which will compile and run without Exception? (Choose all that apply.)
A. System.out.format("%b", 123);
B. System.out.format("%c", "x");
C. System.out.printf("%d", 123);
D. System.out.printf("%f", 123);
E. System.out.printf("%d", 123.45);
F. System.out.printf("%f", 123.45);
G. System.out.format("%s", new Long("123"));
[ June 22, 2008: Message edited by: Keith Nagle ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: K&B book, page 503 q9
 
Similar Threads
please explain this!!
switch statement
Doubt in thread
Mock -Example Regex metacharacter
Which is Better K&B or K Mugal?