What will be the result of compiling and running the following code:

public final class QTest {
    public static void main(String[] args) {
        new QTest() {
            public void show() {
                System.out.print("2");
            }
        }.show();
    }
    public void show() {
        System.out.print("1");
    }
}
Explanation
Compilation error will occur, because there is an attempt to instantinate an anonimous inner class, which is a subclass of final class QTest. (Classes declared with a final modifier can't have subclasses)

Следи за CodeGalaxy

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

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