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 ");

    private static Test getTest(){
        return null;
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
Sign Up Now
or Subscribe for future quizzes