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
Зареєструйся Зараз
або Підпишись на майбутні тести