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.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes