A

Admin • 833.24K Points
Coach

Q. 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) 0 D. Runtime Exception
  • Correct Answer - Option(A)
  • Views: 36
  • Filed under category Java
  • Hashtags:

Explanation by: Admin

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

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.