B

Bhagwan Das • 4.44K Points
Extraordinary

Q. What is the output for the below code?
public class A{
static{
System.out.println("static");
}

{
System.out.println("block");
}

public A(){
System.out.println("A");
}

public static void main(String[] args){
A a = new A();
}
}

  • (A) A block static
  • (B) static block A
  • (C) static A
  • (D) static A D. A
  • Correct Answer - Option(B)
  • Views: 36
  • Filed under category JAVA

Explanation by: Bhagwan Das
First execute static block, then statement block and then constructor.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.


Question analytics