What will be displayed by the following program?

public class Main {
  {
    System.out.print("1 ");
  }

  Main(){
    System.out.print("2 ");
  }

  public static void main(String[] args) {
    System.out.print("3 ");
    Main m = new Main();
    System.out.print("4 ");
  }

  static {
    System.out.print("5 ");
  }
}
Explanation
The static block is initialized firs, then the control is passed to main, the constructor is called and the class is initialized, the function inside the constructor is called, the end of the work.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes