Oracle Certified Professional Java Se 8 Programmer · Free Practice Question Easy
Question 38
Which of the following will always represent Locale object for English in US?
Select 2 options.
-
A
Locale l5 = new Locale("en", "US"); -
B
Locale l3 = Locale.getInstance("us"); -
C
Locale l2 = new Locale(Locale.US); -
D
Locale l4 = Locale.getDefault(); -
E
Locale l1 = Locale.US;
Reveal correct answers
Correct answers: A, E
Explanation
Locale.US;
✓ Locale.US represents a Locale instance for en_US.
new Locale(Locale.US);
✗ There is no Locale constructor which accepts a Locale object.
Locale.getInstance("us");
✗ There is no getInstance method in Locale class.
Locale.getDefault();
✗ It will not always return Locale for en_US, it depends on the default locale of JVM.
new Locale("en", "US");
✓ This definitely creates a Locale instance for en_US.
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
