Start Coding Now

Super Keyword in Java - Accessing Parent Class

How to use the "super" keyword in Java to access inherited members or invoke parent class constructors.

Using 'super' keyword

The super keyword refers to the superclass (parent) objects.

Uses:

  • Call superclass methods that are overridden.
  • Access superclass fields if shadowed.
  • Invoke superclass constructor.
  • class Animal { // Superclass (parent)
      public void animalSound() {
        System.out.println("The animal makes a sound");
      }
    }

    class Dog extends Animal { // Subclass (child) public void animalSound() { super.animalSound(); // Call the superclass method System.out.println("The dog says: bow wow"); } }

    Frequently Asked Questions