Is there a Convention or common way for using super class functions and members?

For example the super class has the function protected void Foo() and protected int myInt;

In subclass would I want to refer to those simply as the Foo() and myInt or as super.foo() and super.myInt . Or some other way.

  • 2
    The best convention by far is to avoid using superclass functions where you can. en.wikipedia.org/wiki/Fragile_base_class en.wikipedia.org/wiki/Composition_over_inheritance You appear to be using Java so take a look at Interfaces. – itsbruce Nov 8 '13 at 9:55
  • Sharing your research helps everyone. Tell us what you've tried and why it didn’t meet your needs. This demonstrates that you’ve taken the time to try to help yourself, it saves us from reiterating obvious answers, and most of all it helps you get a more specific and relevant answer. Also see How to Ask – gnat Nov 8 '13 at 11:35

The only difference I can think of between using Foo() or super.Foo() is what happens if, at some time in the future, you add a method called Foo() to the subclass for some reason, overriding that in the superclass.

If you're likely to want the call to begin using the more specific overridden implementation, which is the most likely option, you would probably want to use just Foo(). If, for some reason, you want to make it explicit that the call always call the superclass function, even if gets overridden in the subclass in the future, then you can use super.Foo() to make this explicit.

Other than this I don't think there's really any difference in how you call it, other than issues of readability etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.