Examveda
Examveda

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

B. 5

C. 0

D. Runtime Exception

E. None of these

Answer: Option A

Solution(By Examveda Team)

A variable declared in a static initializer is not accessible outside its enclosing block.

This Question Belongs to Java Program >> Declaration And Access Control

Join The Discussion

Related Questions on Declaration and Access Control