Java OCA OCP Practice Question 123

Question

Which of the following declarations does not compile?

  • A. double num1, int num2 = 0;
  • B. int num1, num2;
  • C. int num1, num2 = 0;
  • D. int num1 = 0, num2 = 0;


A.

Note

Option A does not compile.

Java does not allow declaring different types as part of the same declaration.

The other three options show various legal combinations of combining multiple variables in the same declarations with optional default values.




PreviousNext

Related