Java OCA OCP Practice Question 2246

Question

Given the following code, Java will try to find a matching resource bundle.

Which order will Java search to find a match?

Locale.setDefault(new Locale("en")); 
ResourceBundle.getBundle("AB", new Locale("fr")); 
  • A. AB.class, AB.properties, AB_en.properties, AB_fr.properties
  • B. AB.properties, AB.class, AB_en.properties, AB_fr.properties
  • C. AB_en.properties, AB_fr.properties, AB.class, AB.properties
  • D. AB_fr.properties, AB.class, AB.properties, AB_en.properties
  • E. AB_fr.properties, AB_en.properties, AB.class, AB.properties
  • F. AB_fr.properties, AB_en.properties, AB.properties, AB.class


E.

Note

First, Java looks for the requested resource bundle, which is AB_fr.class and then AB_fr.properties.

This rules out Options A, B, and C.

Next, Java looks for the default locale's resource bundle, which is AB_en.properties.

This rules out Option D.

Java looks for the default resource bundle.

First, Java checks for a Java class file resource bundle and then moves on to the property file.

Therefore, Option F is incorrect, and Option E is the answer.




PreviousNext

Related