Java OCA OCP Practice Question 2785

Question

Assume that all bundles mentioned in the answers exist and define the same keys.

Which one will be used to find the key in line 8?

6:    Locale.setDefault(new Locale("en", "US")); 
7:    ResourceBundle b = ResourceBundle.getBundle("Main"); 
8:    b.getString("name"); 
  • A. Main.properties
  • B. Main_en.java
  • C. Main_en.properties
  • D. Abc.properties
  • E. Abc_en_US.properties
  • F. The code does not compile.


B.

Note

Java will first look for the most specific matches it can find, starting with Main_en_ US.java and then Main_en_US.properties.

Since neither is found, it drops the country and looks for Main_en.java.

Since a match is found, there is no reason to go on to the next one, which is Main_en.properties.




PreviousNext

Related