Java OCA OCP Practice Question 2787

Question

Suppose that we have the following property files and code. Which bundles are used on lines 8 and 9 respectively?

Main.properties /*from  w ww  .j a  v  a2  s.  c o m*/
name=The Dolphin 
age=0 


Main_en.properties 
name=Dolly 
age=4 


Main_fr.properties 
name=Dolly 
5:    Locale fr = new Locale("fr"); 
6:    Locale.setDefault(new Locale("en", "US")); 
7:    ResourceBundle b = ResourceBundle.getBundle("Main", fr); 
8:    b.getString("name"); 
9:    b.getString("age");? 
  • A. Main.properties and Main.properties
  • B. Main.properties and Main_en.properties
  • C. Main_en.properties and Main_en.properties
  • D. Main_fr.properties and Main.properties
  • E. Main_fr.properties and Main_en.properties
  • F. The code does not compile.


D.

Note

Java will use Main_fr.properties as the matching resource bundle on line 7 because it is an exact match on the language of the requested locale.

Line 8 finds a matching key in this file.

Line 9 does not find a match in that file, and therefore it has to look higher up in the hierarchy.

Once a bundle is chosen, only resources in that hierarchy are allowed.




PreviousNext

Related