In this below code:
interface I1 {
void m1();
}
interface I2 {
void m2();
}
abstract class A implements I1, I2 {
public void m1() {
System.out.println("Inside A: m1()");
}
}
class B extends A {
public void m1() {
System.out.println("Inside B: m1()");
}
public void m2() {
System.out.println("Inside B: m2()");
}
}
public class Test {
public static void main(String[] args) {
// invoke A's m1()
A a = new B();
a.m1();
}
}
How can I just invoke m1() in A without making any changes to class B i.e. we can't add super.m1() in the m1() in B? With my code I just get the m1() in B because of dynamic method dispatch or runtime polymorphism.
An interviewer asked me this question. And I told him that it wasn't possible to do so but he replied that there is a way but didn't told me how.