nerdexam
Oracle

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

Which two code blocks correctly initialize a Locale variable?

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)
  • A
    9% (4)
  • B
    14% (6)
  • C
    5% (2)
  • D
    73% (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 - Locale is not a String; you cannot assign a string literal to a Locale variable (compile error).
  • B - Locale.getInstance() does not exist; getInstance is not a method on the Locale class.
  • 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.

Full 1Z0-809 Practice