Java SE 8 Programmer II — Question 18
Which two code blocks correctly initialize a Locale variable?
Answer options
- A. Locale loc1 = "UK";
- B. Locale loc2 = Locale.getInstance("ru");
- C. Locale loc3 = Locale.getLocaleFactory("RU");
- D. Locale loc4 = Locale.UK;
- E. Locale loc5 = new Locale ("ru", "RU");
Correct answer: D, E
Explanation
Option D is correct because it directly references a predefined Locale object for the UK. Option E is also valid as it correctly initializes a new Locale object with the specified language and country. Options A, B, and C are incorrect due to improper initialization methods or calls that do not conform to the Locale class usage.