Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Accessing super-class methods from super-class

Reply
Thread Tools

Accessing super-class methods from super-class

 
 
fi3nd fi3nd is offline
Junior Member
Join Date: Apr 2010
Posts: 1
 
      04-08-2010
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a way to find the class methods of a class, just like'methods' finds the instance methods? Kenneth McDonald Ruby 5 09-26-2008 03:09 PM
Top-Up Methods - Finarea (Voipcheap, internetcalls, etc.) et. al., VOIP Services Question - Top-up Methods News Reader UK VOIP 0 04-10-2006 02:41 PM
Why Petshop Changed all static methods to instance methods when upgrading from version 3.0 to version 3.1? Neo ASP .Net 1 01-07-2005 01:46 AM
Derived methods hiding inherited methods Tron Thomas C++ 10 11-10-2004 09:32 AM
Re: Templates and friends and template methods with private methods. Buster Copley C++ 5 07-07-2003 12:50 AM



Advertisments