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
πŸ’¬ Discuss
βœ… Correct Answer: (A) Compile with error
Explanation: A variable declared in a static initializer is not accessible outside its enclosing block.
Explanation by: Praveen Singh
A variable declared in a static initializer is not accessible outside its enclosing block.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
121
Total Visits
πŸ“½οΈ
1 y ago
Published
πŸŽ–οΈ
Praveen Singh
Publisher
πŸ“ˆ
94%
Success Rate