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