Java OCA OCP Practice Question 807

Question

What is the result of the following?

public static void main(String... args) { 
   String name = "A"; 
   int _number = 001; 
   boolean a$; 
   System.out.println(name + " won. " 
       + _number + " profit? " + a$); 
} 
  • A. The declaration of name does not compile.
  • B. The declaration of _number does not compile.
  • C. The declaration of a$ does not compile.
  • D. The println statement does not compile.
  • E. The code compiles and runs successfully.
  • F. The code compiles and throws an exception at runtime.


D.

Note

Variables are allowed to start with an underscore and are allowed to contain a $.

Therefore, all the variable declarations compile, making Options A, B, and C incorrect.

However, the println() refers to the uninitialized local boolean.

Since local variables are not automatically initialized, the code does not compile, and Option D is correct.




PreviousNext

Related