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.

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Продолжайте изучать
тесты по Java
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты