Java OCA OCP Practice Question 2988

Question

Given:

import java.text.DateFormat;

public class Main {
   public static void main(String[] args) {
      DateFormat df1 = DateFormat.getInstance();
      DateFormat df2 = DateFormat.getInstance(DateFormat.SHORT);
      DateFormat df3 = DateFormat.getDateInstance(DateFormat.FULL);
      DateFormat df4 = DateFormat.getDateInstance(DateFormat.EXTENDED);
   }/*from   w w w. java  2  s  .c o m*/
}

Which are true? (Choose all that apply.)

  • A. Line 2 is not necessary.
  • B. Line 3 is not necessary.
  • C. Compilation fails due to an error on line 6.
  • D. Compilation fails due to an error on line 7.
  • E. Compilation fails due to an error on line 8.
  • F. Compilation fails due to an error on line 9.


B, D, and F are correct.

Note

The DateFormat class is in the java.text package.

The getInstance() method takes no arguments, and it uses the SHORT style by default.

There is no such style as EXTENDED.

Note: We agree that this is largely a memorization question.

For the most part the exam doesn't tend to be so memorization intensive, but this objective tends to be more so.

Take the perspective that once you're done you can forget the details, and later on, when you're using these classes in practice, you'll have that nagging sensation that there are in fact a couple of gotchas in the API.




PreviousNext

Related