What will be printed as a result of compiling and running this code?

public class TestClass {
    public static void main(String[] args) {
        Base sub = new Sub();
        sub.test();
    }
}

class Base {
    public static void test() {
        System.out.println("Base.test()");
    }
}

class Sub extends Base {
    public static void test() {
        System.out.println("Sub.test()");
    }
}
Explanation
For static methods the late binding is uncharacteristically and the compiler selects the type based on the type of the link, and not the type of the assigned object.

Следи за CodeGalaxy

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

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