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

output clarification

m prabhu
Ranch Hand

Joined: Jan 29, 2008
Posts: 79

will it compile and run without exception.please explain the result.
Milan Sutaria
Ranch Hand

Joined: Jul 10, 2008
Posts: 122
how about running it?
answer is ... yes it will run without any error. '%s' invokes the toString() method on the object & so the output will be 123
[ July 22, 2008: Message edited by: Milan Sutaria ]

SCJP 6 83%
m prabhu
Ranch Hand

Joined: Jan 29, 2008
Posts: 79

when compiled:giving the following error.

symbol : method format(java.lang.String,java.lang.Long)
location: class
System.out.format("%s", new Long("123"));
1 error

Please explain
Denis Bogdanov

Joined: Jul 10, 2008
Posts: 8
What Java version do you have? The class PrintStream has the method format() in java 5.
Sandeep Bhandari
Ranch Hand

Joined: Apr 16, 2004
Posts: 201
Use the same version of java as the one of the exam for which you are preparing

SCJP 96% | SCWCD 90%| SCJP mock exams | My SCJP blog
I agree. Here's the link:
subject: output clarification
It's not a secret anymore!