Which code fragment, inserted at line 23, allows the code to compile?

Given:

5. import java.util.Date;
6. import java.text.DateFormat;
21. DateFormat df;
22. Date date = new Date();
23. // insert code here
24. String s = df.format(date);

Which code fragment, inserted at line 23, allows the code to compile?

Given:

5. import java.util.Date;
6. import java.text.DateFormat;
21. DateFormat df;
22. Date date = new Date();
23. // insert code here
24. String s = df.format(date);

Which code fragment, inserted at line 23, allows the code to compile?

A.
df = new DateFormat();

B.
df = Date.getFormat();

C.
df = date.getFormat();

D.
df = DateFormat.getFormat();

E.
df = DateFormat.getInstance();



Leave a Reply 1

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


Matti

Matti

E is correct! DateFormat has no constructor, just fabric method: getInstance()