# 22) Super Keyword

![](/files/-LUdmEhNlvKHKDqskmyc)

![](/files/-LUdmJaC4PNjvXfuKlzl)

```java
package com.gns.sort;

/* Base class vehicle */
class Vehicle {
	int maxSpeed = 120;
}

/* sub class Car extending vehicle */
class Car extends Vehicle {
	int maxSpeed = 180;

	void display() {
		/* print maxSpeed of base class (vehicle) */
		System.out.println("Maximum Speed: " + super.maxSpeed);
	}
}

/* Driver program to test */
public class Test {
	public static void main(String[] args) {
		Car small = new Car();
		small.display();
	}
}
```

```
Output:
Maximum Speed: 120
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.
```

![](/files/-LUdmkHN87iS_rQ-l-tx)

```java
package com.gns.sort;

/* Base class Person */
class Person {
	void message() {
		System.out.println("This is person class");
	}
}

/* Subclass Student */
class Student extends Person {
	void message() {
		System.out.println("This is student class");
	}

	// Note that display() is only in Student class
	void display() {
		// will invoke or call current class message() method
		message();

		// will invoke or call parent class message() method
		super.message();
	}
}

/* Driver program to test */
public class Test {
	public static void main(String args[]) {
		Student s = new Student();

		// calling display() of Student
		s.display();
	}
}
```

```
Output:
This is student class
This is person class
```

![](/files/-LUdn4MbCwTHy97iv-FS)

![](/files/-LUdnAK4fwBjuWjhYbLm)

```java
package com.gns.sort;

/* superclass Person */
class Person {
	Person() {
		System.out.println("Person class Constructor");
	}
}

/* subclass Student extending the Person class */
class Student extends Person {
	Student() {
		// invoke or call parent class constructor
		super();

		System.out.println("Student class Constructor");
	}
}

/* Driver program to test */
class Test {
	public static void main(String[] args) {
		Student s = new Student();
	}
}
```

```
Output:
Person class Constructor
Student class Constructor
```

![](/files/-LUdnRotnRife7bcw5Dq)

![](/files/-LUdnWxSOmsGTM_S46qO)

### Example 1:

![](/files/-LUdnzCia0kCnM_Rj4IR)

### Example 2:

![](/files/-LUdo7MBP-LA_q_rmZne)

### Example 3:

![](/files/-LUdoGFjAoDW09X8-zxU)

### Problems :

![](/files/-LUdoUR8bQzQvhLzDt9w)

![](/files/-LUdpRYbr5C_mRvkvaly)


---

# Agent Instructions: 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-java.gitbook.io/core-java/super.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.
