Java OCA OCP Practice Question 2106

Question

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

Locale.setDefault(new Locale("en", "US")); 
ResourceBundle rb = ResourceBundle.getBundle("Colors"); 
rb.getString("purple"); 
  • A. Colors_en.class
  • B. Colors_en.properties
  • C. Colors_US.class
  • D. Colors_US.properties


A.

Note

Java starts out by looking for a Java file with the most specific match, which is language and country code.

Since there is no such matching file, it drops the country code and looks for a match by language code.

Java looks for bytecode files before properties files.

Option A is the answer.

If it wasn't present, Option B would be the next choice.

Options C and D would never be considered, as a locale doesn't just have a country code.




PreviousNext

Related