- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
super keyword in Java
- super variable refers immediate parent class instance.
- super variable can invoke immediate parent class method.
- super() acts as immediate parent class constructor and should be first line in child class constructor.
When invoking a superclass version of an overridden method the super keyword is used.
Example
class Animal { public void move() { System.out.println("Animals can move"); } } class Dog extends Animal { public void move() { super.move(); // invokes the super class method System.out.println("Dogs can walk and run"); } } public class TestDog { public static void main(String args[]) { Animal b = new Dog(); // Animal reference but Dog object b.move(); // runs the method in Dog class } }
Output
This will produce the following result −
Animals can move Dogs can walk and run
- Related Articles
- Equivalent of Java Super Keyword in C#
- Role of super Keyword in Java Inheritance
- Super keyword in JavaScript?
- What are the uses of super keyword in java?
- Super keyword in Dart Programming
- What are the three usages of the super keyword in Java?
- Why can't we use the "super" keyword is in a static method in java?
- Difference between super() and this() in Java
- Are ‘this’ and ‘super’ keywords in Java?
- instanceof Keyword in Java
- Private Keyword in Java
- Protected Keyword in Java
- Public Keyword in Java
- static Keyword in Java
- synchronized Keyword in Java

Advertisements