0

Well, we all know that we can use the function of father class with "super", but how to use a function of grandfather class? Using "super.super" has no effects. I'm a new Java learner, thanks for your response.

Eternally_Ascend
  • 163
  • 1
  • 2
  • 7
  • 1
    Show some code. – Abhijit Sarkar Aug 08 '20 at 03:05
  • Well, I do not want to get an answer like "Add a function linked to grandfather class in father class." I want a solution in current class, although I don't know whether there exists a method. – Eternally_Ascend Aug 08 '20 at 03:11
  • I'm not 100% positive your question is a duplicate, but what you specifically describe (i.e. `super.super`) is deliberately not possible (as explained in the duplicates). And there's no other way to directly call a superclass' superclass' implementation of an overridden method when said method is overridden in each ancestor class (if there was a way, it would have been `super.super`). – Slaw Aug 08 '20 at 04:02

1 Answers1

1

What you are asking is not possible, it is not allowed by Java language (though allowed by JVM).

One way would be to add a super call in your parent as well, so calling super from child, will call super of parent which will call the method you need in grandparent. Thats what came to my mind.

If you do not want to touch your parent class, and want a solution only in child class, it is not possible. I would suggest changing your class designs.

srv236
  • 509
  • 3
  • 5