class P {
static void printS1(){System.out.print("P.printS1 ");}
void printS2() {System.out.print("P.printS2 ");}
void printS1S2(){printS1();printS2();}
}
class Q extends P {
static void printS1(){System.out.print("Q.printS1 ");}
void printS2(){System.out.print("Q.printS2 ");}
public static void main(
String[] args) {
new Q().printS1S2();
}}
For the code above, the answer is
Prints: P.printS1 Q.printS2
The explaination says that If the method called is a static member of the class where the invocation expression occurs, then that is the implementation of the method that is invoked at run-time regardless of the run-time type of the object but the method printS1S2()is also a part of the class Q which inherits it from class P so shouldn't the method printS1() of class Q be called and the answer should be Q.printS1 Q.printS2?
Pls help me understand.
Thanks.