What happens when you try to compile and run this code:

public class QTest {

    public static void main(String[] args) {
        new QTest();

    static {
Static initialization blocks are executed before calling the main method and before the first instance of the class in which they are declared. Non-static initialization blocks are executed when the class is instantiated. Therefore, in this example, the first "System.out.print("3");" will be executed and then starts to work the method main - "System.out.print("2");" will be executed and finally, during the instillation of the exemplar of QTest System.out.print("1");" will be executed.

The correct answer - "The console will indicate 321".

Следи за CodeGalaxy

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

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