Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Calling super for method in grandfather class, skipping parent class?

843785Oct 14 2008 — edited Oct 14 2008
Hi all,

When a child class overrides a method in the parent class, they sometimes override the method completely, and they sometime call super to use the parent class's method as well.

I have a class where I completely want to override the parent's version of the method, but I do want to call super on the grandfather's method. Is this possible?

I've tried
public void myMethod(){
   MyGrandfather.super.myMethod();
   // do something else
}
and
public void myMethod(){
   ((MyGrandfather)this).myMethod();
   // do something else
}
but neither seems to work (the first doesn't compile, the second fails at runtime.

Any suggestions?

Thanks!
Time
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 11 2008
Added on Oct 14 2008
59 comments
2,531 views