> For the complete documentation index, see [llms.txt](https://gyansetu-selenium.gitbook.io/selenium-testing/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gyansetu-selenium.gitbook.io/selenium-testing/super-keyword.md).

# super keyword

&#x20;In Java, super keyword is used to refer to immediate parent class of a class.

\
&#x20;The keyword “super” came into the picture with the concept of Inheritance. It is majorly used in the following contexts:

&#x20;**1**. With variables&#x20;

**2**. With methods&#x20;

**3.** With constructors&#x20;

**1**. Super with variables: This scenario occurs when a derived class and base class has same data members. In that case there is a possibility of ambiguity for the JVM. We can understand it more clearly using below example:

![](/files/-LTfcz0mbYvBTh1xJ-2l)

#### &#x20;Output:

&#x20;Maximum Speed: 120\
&#x20;In the above example, both base class and subclass have a member maxSpeed. We could access maxSpeed of base class in sublcass using super keyword.

&#x20;**2. Super with methods:** This is used when we want to call parent class method. So whenever a parent and child class has same named methods then to resolve ambiguity we use super keyword. Below example help you to understand the said usage of super keyword.

![](/files/-LTfdG0rrEN2qzgP9gRq)

#### &#x20;} Output:

&#x20;This is student class\
&#x20;This is person class <br>

In the above example, we have seen that if we only call method message() then, the current class message() is invoked but with the use of super keyword, message() of superclass could also be invoked.

#### &#x20;Important points:&#x20;

**1.** Call to super() must be first statement in Derived(Student) Class constructor.&#x20;

**2.** If a constructor does not explicitly invoke a superclass constructor, the Java compiler automatically inserts a call to the no-argument constructor of the superclass. If the superclass does not have a no-argument constructor, you will get a compile-time error. Object does have such a constructor, so if Object is the only superclass, there is no problem.&#x20;

**3.** If a subclass constructor invokes a constructor of its superclass, either explicitly or implicitly, you might think that a whole chain of constructors called, all the way back to the constructor of Object. This, in fact, is the case. It is called constructor chaining.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gyansetu-selenium.gitbook.io/selenium-testing/super-keyword.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
