java - How do we call a super class method if we already have a super class of sub class? -
my question if there child class extend father class , extended grandfather class how can child class directly access grandfather's method.
this best illustrated example:
public class gf { public void one() { ... } public void two() { ... } } public class f extends gf { public void two() { ... } } public class c extends f { public void one() { super.one(); // calls 1 in gf } public void two() { super.two(); // calls 2 in f } }
the syntax calling overridden method within subclass super.method(....)
. can call first level overridden method. if method override, cannot call 2nd-level override; e.g. there no way c.two()
directly call gf.two()
. can't reflectively, , jvm bytecodes won't allow it.
Comments
Post a Comment