Calling Super-class Methods in Java Programming

Calling Super-class Methods in Java Programming

Previous Home Next

 


We use the keyword super to call the superclass version of an overridden method
  super refers to the object that contains the method.
It can only be used to refer to methods and variables in the superclass.

The major use of super is to override a method with a new method that extends the behavior of the inherited method, instead of replacing that behavior entirely.
 


 
public class GraphicalDice extends PairOfDice {

public void roll()
{
// Roll the dice, and redraw them.
super.roll(); // Call the roll method from PairOfDice.
redraw(); // Call a method to draw the dice.
}



Previous Home Next