Java OCA OCP Practice Question 2578

Question

Given that "it, IT" and "pt" are valid Locale codes, and given:

41.   Date d = new Date();  
42.   DateFormat df;  
43.   Locale[] la = {new Locale("it", "IT"), new Locale("pt")};  
44.   for(Locale l: la) {  
45.      df = DateFormat.getDateInstance(DateFormat.FULL, l);  
46.      System.out.println(d.format(df));  
47.   } 

Which are true? (Choose all that apply.)

  • A. An exception will be thrown at runtime.
  • B. Compilation fails due to an error on line 43.
  • C. Compilation fails due to an error on line 45.
  • D. Compilation fails due to an error on line 46.
  • E. Classes from the java.text package are used in this code.
  • F. Classes from the java.util package are used in this code.


D, E, and F are correct.

Note

It's okay to mix the two types of Locale on line 43.

On line 46, we should use the DateFormat instance to invoke the format() method on the Date instance.

The rest of the code is legal.




PreviousNext

Related