Java OCA OCP Practice Question 223

Question

Of the types double, int, long, and short, how many could fill in the blank(XXXX) to have this code output 0?

static XXXXXX defaultValue; 

public static void main(String[] args) { 
    System.out.println(defaultValue); 
} 
  • A. One
  • B. Two
  • C. Three
  • D. Four


C.

Note

Since defaultValue is an instance variable, it is automatically initialized to the corresponding value for that type.

For double, that value is 0.0.

By contrast, it is 0 for int, long, and short.

Option C is correct.




PreviousNext

Related