Java OCA OCP Practice Question 182

Question

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

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


A.

Note

Since defaultValue is a local variable, it is not automatically initialized.

That means the code will not compile with any type.

Option A is correct.

If this was an instance variable, Option C would be correct as int and short would be initialized to 0 while double would be initialized to 0.0.




PreviousNext

Related