Java OCA OCP Practice Question 2114

Question

How many lines does the following print out?.

3:   Locale.setDefault(Locale.KOREAN); 
4:   System.out.println(Locale.getDefault()); 
5:   Locale.setDefault(new Locale("en", "AU")); 
6:   System.out.println(Locale.getDefault()); 
7:   Locale.setDefault(new Locale("EN")); 
8:   System.out.println(Locale.getDefault()); 
  • A. None; it does not compile.
  • B. One followed by an exception
  • C. Two followed by an exception
  • D. All three


D.

Note

This code compiles and runs without exception, making Option D the answer.

Line 3 uses a predefined Locale constant.

Line 5 passes a language and country code for English in Australia.

Line 7 incorrectly passes capital letters as a language code.

However, Java automatically converts it to lowercase without throwing an exception.

The three lines printed by the code are ko, en_US and en.




PreviousNext

Related