Java OCA OCP Practice Question 2544

Question

An application supports resource bundles for languages French ( fr), Spanish (es), and English (en).

The following are the listings of the corresponding resource bundles:.

#GlobalBundle_en.properties
greeting=Hi

#GlobalBundle_fr.properties
greeting=Salut

#GlobalBundle_es.properties
greeting=Hola

Given that the default locale is Spanish, what's the output of the following code?.

Locale.setDefault(new Locale("ja", "JP"));
Locale newLocale = Locale.getDefault();
ResourceBundle messages = ResourceBundle
                                  .getBundle("GlobalBundle", newLocale);
System.out.println(messages.getString("greeting"));
a  Hi
b  Salut
c  Hola
d  No output
e  Compilation error
f  Runtime exception


f

Note

The application defines resource bundles to support languages French (fr), Spanish (es), and English (en).

The following code changes the default locale for the application to Locale.

JAPAN, with the language as Japanese:.

Locale.setDefault(new Locale("ja", "JP"));

When the code retrieves the default locale for the same application, it returns Locale.JAPAN and not the earlier default locale language, Spanish:.

Locale newLocale = Locale.getDefault();

Because no matching resource bundle for the language Japanese and country Japan can be found, this application throws a MissingResourceException at runtime.




PreviousNext

Related