File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

mock exam confusion

 
Rachel Glenn
Ranch Hand
Posts: 95
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The sierra/bates mock exam says this WILL compile:




but I know this statement does NOT compile:



Can someone explain why? I thought the rules for both format() and print() were the same...
 
Greg Charles
Sheriff
Posts: 2984
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you mean format() and printf() behave the same. Both print() and println() in the PrintStream class (which is what System.out is) have a different interface. In particular, they only take a single parameter, so when you try to call System.out.print() with two parameters, the compiler complains.
 
Rachel Glenn
Ranch Hand
Posts: 95
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greg Charles wrote:I think you mean format() and printf() behave the same. Both print() and println() in the PrintStream class (which is what System.out is) have a different interface. In particular, they only take a single parameter, so when you try to call System.out.print() with two parameters, the compiler complains.


oops...

Sooo.....

-print() and println() each take a single argument (no formatting characters allowed!)
-format() takes multiple arguments and returns a string
-printf() formats AND prints...

right?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic