File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

K&B book, page 503 q9

 
Keith Nagle
Ranch Hand
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Noam Wolf
Ranch Hand
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Keith, can you please provide the question and possible answers? I don't have a copy of the book handy.
 
Antonio Tercero
Ranch Hand
Posts: 110
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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().
 
Keith Nagle
Ranch Hand
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8898
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Keith Nagle
Ranch Hand
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic