Hello,
consider this example (theoretically!!!):
Of course, the output is:
B::b
A::b
Is there any way to access A::b (as it would be in C++) from A.a in this case? I know that Java always uses dynamic binding etc., however, I'm interested if there exists better workaround than that above.
best regards,
Krzysztof Zmiek
consider this example (theoretically!!!):
Code:
class A {
public void a() {
b(); // calls B::b if 'this' is instance of B
// silly workaround:
((B) this).help();
}
public void b() {
System.out.println("A::b");
}
}
class B extends A {
@Override
public void a() {
super.a();
}
@Override
public void b() {
System.out.println("B::b");
}
public void help() {
super.b();
}
}
public class Test {
public static void main(String args[]) {
A a = new B();
a.a();
}
}
Of course, the output is:
B::b
A::b
Is there any way to access A::b (as it would be in C++) from A.a in this case? I know that Java always uses dynamic binding etc., however, I'm interested if there exists better workaround than that above.
best regards,
Krzysztof Zmiek