nerdexam
Oracle

1Z0-851 · Question #62

Given: 12. Date date = new Date(); 13. df.setLocale(Locale.ITALY); 14. String s = df.format(date); The variable df is an object of type DateFormat that has been initialized in line 11. What is the…

The correct answer is D. Compilation fails because of an error in line 13. The method setLocale(Locale) is undefined for the type DateFormat. It should be done in line 11 like this DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, Locale.ITALY);

Analyzing and Troubleshooting System Problems

Question

Given: 12. Date date = new Date(); 13. df.setLocale(Locale.ITALY); 14. String s = df.format(date); The variable df is an object of type DateFormat that has been initialized in line 11. What is the result if this code is run on December 14, 2000?

Options

  • AThe value of s is 14-dic-2000.
  • BThe value of s is Dec 14, 2000.
  • CAn exception is thrown at runtime.
  • DCompilation fails because of an error in line 13.

How the community answered

(36 responses)
  • A
    3% (1)
  • B
    11% (4)
  • C
    3% (1)
  • D
    83% (30)

Explanation

The method setLocale(Locale) is undefined for the type DateFormat. It should be done in line 11 like this DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, Locale.ITALY);

Topics

#Java DateFormat#Locale#setLocale#compilation error

Community Discussion

No community discussion yet for this question.

Full 1Z0-851 Practice