Java OCA OCP Practice Question 2471

Question

Given:.

1. import java.io.*;  
2. import java.util.*;  
3. import static java.lang.Short.*;  
4. import static java.lang.Long.*;  
5. public class Main {  
6.   public static void main(String[] args) {  
7.     long x = 123456789;  
8.     short y = 22766;  // maximum value of a short is 32767  
9.     System.out.printf("%1$+10d %2$010d ", x, MAX_VALUE - y);  
10.     System.out.println(new Date());  
11.   }  // w w  w.  j  a v a  2  s  . c  om
12. } 

Which are true? (Choose all that apply.)

  • A. Compilation fails.
  • B. The output will include "+"
  • C. The output will include "10001"
  • D. The output will include "0000010001"
  • E. The output will include today's date.
  • F. The output will include the number of milliseconds from January 1, 1970 until today.


A is correct.

Note

Both Short and Long have static MAX_VALUE fields, so the reference to MAX_ VALUE in line 9 is ambiguous.

(If line 4 was removed, the answer would be B, C, D, and E.).




PreviousNext

Related