1

I am using inherited codes which cannot be modified. It is being overrided many times. I want to invoke a specific overrided method of a super class (not a direct super class).

public class SuperSuperClass
{
  ...
  public doSomething()
  {
     //Does something that I want
  }
}

public class SuperClass extends SuperSuperClass
{
  ...
  public doSomething()
  {
     //Does something I do not want
     super.doSomething();
  }
}

public class SubClass extends SuperClass
{
  ...
  public doSomething()
  {
    SuperSuperClass.doSomething();  // is this possible?
  }
}

The SuperClass.doSomething() does something I do not want before itself calling SuperSuperClass.doSomething(). Is there a way I can invoke SuperSuperClass.doSomething() from SubClass?

Prophet
  • 32,350
  • 22
  • 54
  • 79
Kirasaki
  • 23
  • 2
  • Thanks. I tried searching for similar questions but nothing matches. I didn't use the "correct" keywords. – Kirasaki May 21 '14 at 21:25
  • @user3662592 That's the *polymorphism* in JAVA. A overridden method is called based on actual object not on the reference. – Braj May 21 '14 at 21:30

1 Answers1

0

The answer to your question is "no". In Java there is no way to express that you want to invoke an instance method that was defined in some specific class that is part of your inheritance hierarchy. The language provides no way to express that.

Jeff Scott Brown
  • 26,804
  • 2
  • 30
  • 47