1Z0-819 · Question #98
Which two statements set the default locale used for formatting numbers, currency, and percentages? (Choose two.)
The correct answer is B. Locale.setDefault(new Locale.Builder().setLanguage("en").build()); C. Locale.setDefault(new Locale.Builder().setLanguage("en").setRegion("CA").build()). Options B and C are correct because Locale.setDefault() requires a Locale object as its argument, and both use Locale.Builder - the modern, standards-compliant way to construct one - producing valid Locale instances that Java's formatting APIs (numbers, currency, percentages)…
Question
Options
- ALocale.setDefault(Locale.Category.FORMAT, "zh-CN");
- BLocale.setDefault(new Locale.Builder().setLanguage("en").build());
- CLocale.setDefault(new Locale.Builder().setLanguage("en").setRegion("CA").build());
- DLocale.setDefault("en_US");
How the community answered
(25 responses)- A12% (3)
- B84% (21)
- D4% (1)
Explanation
Options B and C are correct because Locale.setDefault() requires a Locale object as its argument, and both use Locale.Builder - the modern, standards-compliant way to construct one - producing valid Locale instances that Java's formatting APIs (numbers, currency, percentages) will use globally.
Why the distractors fail:
- A is wrong on two levels: the two-argument overload
Locale.setDefault(Category, Locale)takes aLocaleas the second argument, not aStringlike"zh-CN". Passing a raw string causes a compile error. - D is wrong for the same core reason: there is no overload of
Locale.setDefault()that accepts aString. Java's API requires an actualLocaleobject, not a locale tag string.
Memory tip: Think of Locale.setDefault() as a typed setter - it only accepts a Locale, never a String. If you see a string passed directly (like "zh-CN" or "en_US"), it's always wrong. The safe builder pattern is new Locale.Builder().setLanguage(...).setRegion(...).build().
Topics
Community Discussion
No community discussion yet for this question.