Java OCA OCP Practice Question 287

Question

Given three resource bundles and a Java class:

Main_en_US.properties: train=subway/*  w w w.j a  v  a 2  s.c  o m*/
Main_en_UK.properties: train=underground
Main_en.properties: ride = ride

1: public class Main {
2:   public static void main(String[] args) {
3:     Locale.setDefault(new Locale("en", "US"));
4:     ResourceBundle rb = ResourceBundle.getBundle("Main",
5:       new Locale("en", "US"));
6:     System.out.print(rb.getString("ride")
         + " " + rb.getString("train"));
7:   }
8: }

Which of the following, when made independently, will change the output to "ride underground"? (Choose all that apply.)

A.   Add train=underground to Main_en.properties
B.   Change line 1 to Locale.setDefault(new Locale("en", "UK"));
C.   Change line 5 to Locale.ENGLISH);
D.   Change line 5 to new Locale("en", "UK"));
E.   Delete file Main_en_US.properties


D is correct.

Note

The code finds resource bundle Main_en_US.properties, which uses Main_en.properties as a parent.

Choice D finds resource bundle Main_en_UK.properties, which uses Main_en.properties as a parent.

A is incorrect because both the parent and child have the same property.

In this scenario, the more specific one gets used.

B is incorrect because the default locale only gets used if the requested resource bundle can't be found.

C is incorrect because it finds the resource bundle Main_en.properties, which does not have any "train" key.

E is incorrect because there is no "ride" key once we delete the parent.

F is incorrect based on the above.




PreviousNext

Related