Java OCA OCP Practice Question 2145

Question

If the key red is in all three of these files, which file will the following code use for the resource bundle?

Locale loc = new Locale("zh", "CN"); 
Locale.setDefault(new Locale("en", "US")); 
ResourceBundle rb = ResourceBundle.getBundle("Colors", loc); 
rb.getString("red"); 
  • A. Colors_EN.properties
  • B. Colors_ZH.properties
  • C. Red_EN.properties
  • D. None of the above. It will throw a MissingResourceException.


D.

Note

Option C is not a valid match for this resource bundle because the base name is Red rather than the requested Colors.

Options A and B are not valid matches because they contain uppercase letters for the language code while Java requires lowercase.

Since none match, Option D is correct, and the code throws an exception at runtime.




PreviousNext

Related