Given:
18. import java.util.Date;
19. import java.text.DateFormat;
20.
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();
Explanation:
A:
Main.java:23: java.text.DateFormat is abstract; cannot be instantiated
df = new DateFormat();
^
1 errorB:
Main.java:23: cannot find symbol
symbol : method getFormat()
location: class java.util.Date
df = Date.getFormat();
^
1 errorC:
Main.java:23: cannot find symbol
symbol : method getFormat()
location: class java.util.Date
df = date.getFormat();
^
1 errorD:
Main.java:23: cannot find symbol
symbol : method getFormat()
location: class java.text.DateFormat
df = DateFormat.getFormat();
^
1 errorE:
compiled successfully