Inheritance misunderstanding

Discussion in 'Spigot Plugin Help' started by Gush, Jul 2, 2015.

  1. I'm working on a plugin and I'm fairly new to Java development, however I'm having an issue understanding superclass inheritance.

    Lets say I have a superclass "Person" with

    a() {
    say("hello");

    and a subclass "Jock" of Person with a(){
    say("what's up");
    }

    If my person is an instance of Jock shouldn't it say("hello") then ("what's up") since I didn't put the @Override above the a() method in "Jock".

    So, I guess my thought is that if the subclass doesn't @Override then it does the superclass first then the subclass, but if you have @Override then it would ignore the superclass and do what's in the method for the subclass only. If this is incorrect, how can I achieve that same mentality?
     
  2. @Gush
    This is better suited to Plugin Development, but it works here too I suppose.

    As for your actual question, it will override even without the annotation, as long as the method name and arguments are identical, it's like laying it on top of the old method. The top layer always gets called.
     
  3. To add on, the @Override annotation is simply there to through a compiler error of the superclass changes and the subclass doesn't (wasn't updated to a new API version, forgot, etc.) rather than just creating a bunch of weird bugs.
     
    • Like Like x 1
    • Agree Agree x 1
  4. I think I get it now so my subclass if I wanted it to do the superclasses identical method I'd just have to refer to the super's method and then do what i want. Thanks guys. I thought about it. Really appreciate the help.
     
  5. If you want it to have identical function to the superclass, just don't implement. If you want it to have identical function in addition to it's own then call it on "super" somewhere in your custom method.