Which two code blocks correctly initialize a Locale var…

Which two code blocks correctly initialize a Locale variable?

Which two code blocks correctly initialize a Locale variable?

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”);



Leave a Reply 4

Your email address will not be published. Required fields are marked *


KashiHide

KashiHide

D, E

smh

smh

please explain why D, E answers. Thank you for help.

andrei

andrei

D, E

There are four possibilities to create a Locale:

// 1) Creating locale object using constructor
Locale locale1 = new Locale(“en”);
Locale locale2 = new Locale(“RO”, “MD”); //bad style to use Uppercase for language
Locale locale3 = new Locale(“no”, “NORWAY”, “NY”);

// 2) A local object from Locale.Builder
Locale locale4 = new Locale.Builder().setLanguage(“RO”).setRegion(“RO”).build();

// 3) Locale from forLanguageTag method
Locale locale5 = Locale.forLanguageTag(“en-US”);

// 4) Using Locale Constant
Locale locale6 = Locale.CHINA;