Given class A { static String s() { return “A”; } } class B extends A { static String s() { return “B”; } }, what does A o = new B(); System.out.println(o.s()); print?
Correct answer D. A
Explanation
Static methods are hidden rather than overridden. A call made through an expression is bound at compile time using its static type, here A, and the object is ignored, so A is printed. The code compiles, though IDEs commonly flag it, and writing A.s() would make the real meaning obvious. Dynamic dispatch applies only to instance methods.
Answer checked How we write and check questions
Discussion