1Z0-809 · Question #115
Which two code blocks correctly initialize a Locale variable?
The correct answer is D. Locale loc4 = Locale.UK; E. Locale loc5 = new Locale ("ru", "RU"). D is correct because Locale.UK is one of several predefined static constants on the Locale class (others include Locale.US, Locale.FRANCE, etc.), making it a direct, type-safe assignment. E is correct because new Locale("ru", "RU") uses the valid two-argument constructor that…
Question
Options
- ALocale loc1 = "UK";
- BLocale loc2 = Locale.getInstance("ru");
- CLocale loc3 = Locale.getLocaleFactory("RU");
- DLocale loc4 = Locale.UK;
- ELocale loc5 = new Locale ("ru", "RU");
How the community answered
(44 responses)- A9% (4)
- B14% (6)
- C5% (2)
- D73% (32)
Explanation
D is correct because Locale.UK is one of several predefined static constants on the Locale class (others include Locale.US, Locale.FRANCE, etc.), making it a direct, type-safe assignment. E is correct because new Locale("ru", "RU") uses the valid two-argument constructor that accepts a lowercase language code followed by an uppercase country code.
Why the distractors fail:
- A -
Localeis not aString; you cannot assign a string literal to aLocalevariable (compile error). - B -
Locale.getInstance()does not exist;getInstanceis not a method on theLocaleclass. - C -
Locale.getLocaleFactory()is completely fabricated; no such method exists in the Java API.
Memory tip: Think of two valid patterns - constant (predefined field like Locale.UK) and constructor (new Locale("language", "COUNTRY")). Any method name on Locale you don't recognize (like getInstance or getLocaleFactory) is almost certainly a distractor, since the real factory-style alternative is Locale.forLanguageTag("ru-RU") - which none of the options above used correctly.
Community Discussion
No community discussion yet for this question.