nerdexam
Oracle

1Z0-851 · Question #21

Given: import java.util.Date; 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…

The correct answer is E. df = DateFormat.getInstance(). See the full explanation below for the reasoning.

Question

Given: import java.util.Date; 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?

Options

  • Adf = new DateFormat();
  • Bdf = Date.getFormat();
  • Cdf = date.getFormat();
  • Ddf = DateFormat.getFormat();
  • Edf = DateFormat.getInstance();

How the community answered

(46 responses)
  • A
    9% (4)
  • B
    2% (1)
  • C
    2% (1)
  • D
    7% (3)
  • E
    80% (37)

Community Discussion

No community discussion yet for this question.

Full 1Z0-851 Practice