Partial Java Override

When overriding a method in Java, you can call "original." For instance:

public class A extends B{

  @Override
  public void foo(){
    System.out.println("yep");
    // Then execute foo() as it defined in B
  }

}
+5
source share
6 answers
public class A extends B{

  @Override
  public void foo(){
    System.out.println("yep");
    super.foo(); // calls the method implemented in B
  }  
}
+12
source

Just call super.methodName()to call the version of this supertype method.

public class A extends B{
  @Override
  public void foo(){
    System.out.println("yep");
    super.foo(); // Here you call the supertype foo()
  }
}

Also, this is not a “partial" method override. You completely override it, but you just use some of the parent functions.

+7
source

Keywork super

super.foo();
+3

super.foo().

+2

super.foo();
+1

:

super.foo()
+1

All Articles