Accessing super-class methods from super-class

Joined
Apr 8, 2010
Messages
1
Reaction score
0
Hello,

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,981
Messages
2,570,187
Members
46,728
Latest member
FernMcmull

Latest Threads

Top