#284 Calling a Static Method Through an Object Reference

Companies:
Unknown company
Themes:
JavaJava BasicsCode Review

What will be printed?

Java
public class A1 {

    public static void print() {
        System.out.println("Static");
    }

    public static void main(String[] args) {
        A1 a = null;
        a.print();

        A1 b;
        b.print();

        A1 c = new A1();
        c.print();
    }
}

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in