Java: Accessing member in parent class

If your method overrides one of its parent class’s methods, you can invoke the overridden method through the use of the keyword super.

package javaapplication33;

public class Music {

    public class Rock {

        public void printout() {
            System.out.println("Printed in Rock Class.");
        }
    }

    public static class Metal extends Rock {

        // overrides printout in Superclass
        public void printout() {
            super.printout();
            System.out.println("Printed in Metal Class");
        } 
    }
    
    public static void main(String[] args) {
        
            Metal s = new Metal();
            s.printout();
        }
}

super

 

 

Series Navigation<< Java: Method Overiding
Java: Constructing a subclass >>