Java OCA OCP Practice Question 64

Question

What is the output of the following code snippet?

String tree = "abc"; 
int count = 0; 
if (tree.equals("abc")) { 
   int height = 55; 
   count = count + 1; 
} 
System.out.print(height + count); 
  • A. 1
  • B. 55
  • C. 56
  • D. It does not compile.


D.

Note

The height variable is declared within the if-then statement block.

Therefore, it cannot be referenced outside the if-then statement and the code does not compile.




PreviousNext

Related