18. What is the output of the following code snippet?
String tree = "pine";
int count = 0;
if (tree.equals("pine")) {
int height = 55;
count = count + 1;
}
System.out.print(height + count);
A. 1
B. 55
C. 56
D. It does not compile.
tree.equals("pine") doğrudur ve if koşunula girer.İçeride 1 adet local variable declare edilip initialize edilmiş . Height ve count adlı değişkene bir fazlası atanmış . If kod bloğunun scope'undan çıkıldıktan sonra height adlı değişkene erişilmeye çalışılmış ama bu hatadır çünkü height değişkeni if kod bloğunun arasında kaldı bunun dışından erişemeyiz.Cevap D