Vidyalelo
Java Programming · Q50

Declaration and Access Control

Programming · Java Programming · question 50

Q50

What will be the output for the below code? public class Test static int a = 5; public static void main(String[] args) System.out.println(a);

A.
Compile with error
Answer
B.
5
C.
0
D.
Runtime Exception
E.
None of these

Answer: Option A

Solution

Answer: Option A
Solution:
A variable declared in a static initializer is not accessible outside its enclosing block.