I have a 3rd-party library class, which I need to extend with my own implementation. The library class I want to extend is itself a subclass of another library base class.
I want the functionality that the base class provides but not that of the subclass. Is there a way to write my overridden method, such that I can call directly to the (grandparent) base class (LibraryBaseClass) from my subclass?
class LibraryBaseClass
{
protected void method() // want to call this method
{
System.out.println( "LibraryBaseClass" );
// ... desired functionality here
}
}
class LibraryClass extends LibraryBaseClass
{
@Override
protected void method() // want to skip this method
{
System.out.println( "LibraryClass" );
// ... undesired functionality here
super.method();
}
}
class MySubClass extends LibraryClass
{
@Override
public void method()
{
System.out.println( "MySubClass" );
super.method(); // would like to call something like LibraryBaseClass.super.method() here
}
}
// using my method here
new MySubClass().method();
I could just copy and paste the code from LibraryBaseClass.method() into MySubClass.method(), but I'd like to avoid that if possible. I cannot directly edit the library code.