Friday, August 27, 2010

Factory Methods

Courtesy of Sun Web Learning Center

Given that he is a valid language code And given the following code fragments:

I. Date d = new Date();
II. Calendar c = new Calender();
III. Locale loc = new Locale("he");
IV. DateFormat df = new DateFormat();

What is true?

A Only fragment I will compile.
B All four fragments will compile.
C Only fragments I and II will compile.
D Only fragments I and III will compile.
E Only fragments II and III will compile.
F Only fragments I, II, and III will compile.

D is correct. Calendar and DateFormat instances are created using getXxx() factory methods. For example:

DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, Locale.FRANCE);
Calendar rightNow = Calendar.getInstance();

No comments:

Post a Comment