Java OCA OCP Practice Question 2965

Question

Which one of the following statements makes use of a factory method?

A.   Locale locale1 = new Locale("it", "", "");
B.   NumberFormat.getInstance(Locale.GERMANY);
C.    Locale locale3 = new Locale.Builder().setLanguageTag("it").build();
D.   Date today = new Date();
e.    Locale locale4 = Locale.ITALIAN;


B.

Note

a factory method creates an instance and returns back.

Using a constructor directly to create an object is not related to a factory method, so a) and D) are not correct.

C) builds a locale and is an example for using the Builder pattern.

e) merely accesses the predefined Locale object; so it's not a method.




PreviousNext

Related