Search
  • +44-7459919437 (UK- WhatsApp & Direct Call) | +91-6383544892 (India - WhatsApp Only) | Email Id : vinothrwins@gmail.com
Vinoth Q.A Academy
  • Home
  • Selenium Java Online Training
  • Self Paced Video Course
    • Selenium Course Curriculum
    • Cypress Course Curriculum
    • Playwright Course Curriculum
  • Tutorials
  • Demo Sites
    • Practice Automation
      • Demo Page Healthcare
      • Registration Form
      • Transaction Details
      • DropDown
      • Mouse Event
      • Keyboard Events
      • Alert and Popup
      • Multiple Windows
      • iFrames
      • Wait WebElement
      • WebTable
  • FAQS
  • About Me & Feedback
    • Placed Students Feedback
    • Online Training Feedback
    • LinkedIn Profile
    • TechTalk
  • Free YouTube Courses
    • Python for Automation
    • Free QA Video Courses
      • Manual Testing
      • Java For Automation
      • Selenium Webdriver
      • TestNG
      • Cucumber BDD
      • UFT(QTP) Automation
    • Free Data Science Courses
      • Artificial Intelligence for Beginners
      • Python For A.I
      • Python Pandas
      • Python NumPy
      • Mathematics for A.I
  • Home
  • Selenium Java Online Training
  • Self Paced Video Course
    • Selenium Course Curriculum
    • Cypress Course Curriculum
    • Playwright Course Curriculum
  • Tutorials
  • Demo Sites
    • Practice Automation
      • Demo Page Healthcare
      • Registration Form
      • Transaction Details
      • DropDown
      • Mouse Event
      • Keyboard Events
      • Alert and Popup
      • Multiple Windows
      • iFrames
      • Wait WebElement
      • WebTable
  • FAQS
  • About Me & Feedback
    • Placed Students Feedback
    • Online Training Feedback
    • LinkedIn Profile
    • TechTalk
  • Free YouTube Courses
    • Python for Automation
    • Free QA Video Courses
      • Manual Testing
      • Java For Automation
      • Selenium Webdriver
      • TestNG
      • Cucumber BDD
      • UFT(QTP) Automation
    • Free Data Science Courses
      • Artificial Intelligence for Beginners
      • Python For A.I
      • Python Pandas
      • Python NumPy
      • Mathematics for A.I

Java

  • What is Java?
  • Why to Learn Java?
  • History of Java
  • Types of Java Applications
  • Naming Conventions
  • Hello World Program
  • Internal Details of Java program
  • What is Java JDK, JRE and JVM ?
  • What is Java Comments ?
  • What is Java Variable?
  • Variable Naming convention
  • Primitive Data Types
  • Non Primitive Data Types
  • Type Casting
  • Java Arithmetic Operators
  • Relational Operators
  • What is logical operators in Java? 
  • What is Assignment Operators in Java? 
  • What is Unary Operators in Java? 
  • What is Ternary Operators in Java?
  • What is Java Control Statements?
  • What are Decision Making statements?
  • What are looping statements?
  • What are Jump statements?
  • What is OOPS concept in Java?
  • Advantages of Java OOPs
  • What is Java Inheritance?
  • What is Java Constructor?
  • What is this keyword?
  • What is Polymorphism?
  • What is super keyword ?
  • What is final keyword? 
  • What are access modifiers?
  • What is Encapsulation? 
  • What is Abstraction? 
View Categories
  • Home
  • Tutorials
  • Java
  • Java
  • What is super keyword ?

What is super keyword ?

What is super keyword ?

The super keyword in Java is used to refer to the immediate parent class object. It is commonly used to:

1. Access Parent Class Methods: To call methods from the parent class that have been overridden in the subclass.

2. Access Parent Class Constructors: To invoke a constructor of the parent class from the subclass constructor.

3. Access Parent Class Fields: To access fields of the parent class if they are hidden by subclass fields.

Key Uses of super #

1. Calling Parent Class Methods: If a method is overridden in the subclass, super can be used to call the parent class’s version of that method.

2. Calling Parent Class Constructor: super can be used in the subclass constructor to explicitly call a constructor of the parent class.

3. Accessing Parent Class Fields: super is used to refer to fields in the parent class that are hidden by fields in the subclass.

Examples #

1. Calling Parent Class Methods

class Animal {

    void makeSound() {

        System.out.println("Animal makes a sound");

    }

}

class Dog extends Animal {

    @Override

    void makeSound() {

        System.out.println("Dog barks");

    }

    void callSuperSound() {

        // Calling the parent class method

        super.makeSound();

    }

}

public class Main {

    public static void main(String[] args) {

        Dog myDog = new Dog();

        myDog.makeSound();       

        myDog.callSuperSound();   

    }

}

Output:
Dog barks
Animal makes a sound

In this example, super.makeSound() is used in the Dog class to call the makeSound method from the Animal class, which has been overridden in Dog.

2. Calling Parent Class Constructor

class Animal {

    Animal() {

        System.out.println("Animal constructor");

    }

}

class Dog extends Animal {

    Dog() {

        // Calling the parent class constructor

        super();

        System.out.println("Dog constructor");

    }

}

public class Main {

    public static void main(String[] args) {

        Dog myDog = new Dog();

    }

}

In this example, super() in the Dog constructor calls the Animal constructor before executing the Dog constructor’s own code.

3. Accessing Parent Class Fields

class Animal {

    String color = "Unknown";

}

class Dog extends Animal {

    String color = "Brown";

    void printColors() {

        // Accessing parent class field

        System.out.println("Parent color: " + super.color);

        // Accessing subclass field

        System.out.println("Current color: " + this.color);

    }

}

public class Main {

    public static void main(String[] args) {

        Dog myDog = new Dog();

        myDog.printColors();

    }

}

In this example, super.color is used to access the color field from the Animal class, while this.color accesses the color field from the Dog class.

Summary #

  • super Keyword: Refers to the parent class’s fields, methods, and constructors.
  • Calling Parent Class Methods: super.methodName()
  • Calling Parent Class Constructor: super()
  • Accessing Parent Class Fields: super.fieldName

The super keyword helps in clarifying which parent class method, field, or constructor you are referring to, particularly in cases where the subclass overrides or hides members of the parent class.

Java
What are your Feelings
Share This Article :
  • Facebook
  • X
  • LinkedIn
What is Polymorphism?What is final keyword? 
Table of Contents
  • Key Uses of super
  • Examples
  • Summary
© Copyright [2018-2025]. All Rights Reserved.