Java OCA OCP Practice Question 2094

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.class
  • B. Colors.properties
  • C. Colors_en_US.class
  • D. Colors_en_US.properties


C.

Note

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

Since this is happening at runtime, it is looking for the corresponding file with a.class extension.

This matches Option C, making it the answer.

If this file was not found, Java would then look for a .properties file with the name, which is Option D.

If neither was found, it would continue dropping components of the name, eventually getting to Options A and B in that order.




PreviousNext

Related