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

public class Test {
    private static String name = "Duke";

    public static void main(String[] args) {
        System.out.println("Hello ");
        System.out.println(getTest().name);
    }

    private static Test getTest(){
        return null;
    }
}
Explanation
Variable name is static, therefore call via method will be replaced with class during the compilation: Test.name. So, no error will occur, and 'Hello Duke' will be printed out.

Следи за CodeGalaxy

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

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