All methods in Java are always virtual. That is, there is no way to call a "super" version of the method from the outside. Execution Adoes not help, because it does not change the type of runtime of the object.
This is probably your best alternative / workaround:
class A {
int n = 10;
public int getN() {
return n;
}
public final int getSuperN() {
return n;
}
}
class B extends A {
int n = 20;
public int getN() {
return n;
}
}
public class Main {
public static void main(String[] args) {
B b = new B();
System.out.println(b.getN());
System.out.println(((A)b).getN());
System.out.println(b.getSuperN());
}
}
source
share