Search This Blog

Saturday, January 29, 2011

Question 17

Which code fragment produces the same output as the following code?

for(int i=0; i< 10; i++)
  System.console().printf("%d", i);
Options :

A. for(int i=0; i< 10; i++)
  System.console().print("%d", i);
B. for(int i=0; i< 10; i++)
  System.console().println("%d", i);
C. for(int i=0; i< 10; i++)
  System.console().write("%d", i);
D. for(int i=0; i< 10; i++)
  System.console().format("%d", i);

Answer : D

This is again an API Question. Console class does not contain print(), println() and write() methods. So Options A, B and C are incorrect. In order to score more in the exam you need to know what all methods are present in Console Class along with their definitions. You can expect atleast one question on Console API.
Java Console Class Methods API for reference.image
Question 17SocialTwist Tell-a-Friend

No comments:

Post a Comment