Java OCA OCP Practice Question 2527

Question

Given the language code for Spanish is es and the country code for Spain is ES, which of the following code options defines a Locale to work with the Spanish language?.

a  Locale locale = new Locale();
   locale.setLanguage("es");
   locale.setCountry("ES");

b  Locale locale = new Locale("es", "ES");

c  Locale locale = new Locale("ES", "es");

d  Locale locale = new Locale("es");


b, d

Note

Option (a) is incorrect because it uses an invalid Locale constructor and methods.

Class Locale defines the following constructors:.

Locale(String language)
Locale(String language, String country)
Locale(String language, String country, String variant)

Option (c) is incorrect.

To create a Locale, language code must be the first argument, and region or country is the second argument.

This option passes language as the second argument.

Option (d) is correct because you need to work with Spanish.

So it's acceptable to pass only this value and leave the region code.




PreviousNext

Related