- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
What is the difference between super and this, keywords in Java?
The this is a keyword in Java which is used as a reference to the object of the current class. Using it you can −
- Differentiate the instance variables from local variables if they have same names, within a constructor or a method.
- Call one type of constructor (parametrized constructor or default) from other in a class. It is known as explicit constructor invocation.
Example
class Superclass { int age; Superclass(int age) { this.age = age; } public void getAge() { System.out.println("The value of the variable named age in super class is: " +age); } }
The super is a keyword in Java which is used as a reference to the object of the super class. Like the this keyword −
- It is used to differentiate the members of superclass from the members of subclass, if they have same names.
- It is used to invoke the superclass constructor from subclass.
Example
class Superclass { int age; Superclass(int age) { this.age = age; } public void getAge() { System.out.println("The value of the variable named age in super class is: " +age); } } public class Subclass extends Superclass { Subclass(int age) { super(age); } public static void main(String argd[]) { Subclass s = new Subclass(24); s.getAge(); } }
Output
The value of the variable named age in super class is: 24
- Related Articles
- Are ‘this’ and ‘super’ keywords in Java?
- Difference between super() and this() in Java
- Difference between super() and this() in java Program
- How to use this and super keywords with lambda expression in Java?
- What is the difference between keywords and reserved words in Java?
- What is the difference between throw and throws keywords in Java?
- How can we use this and super keywords in method reference in Java?
- Difference Between extends and implements keywords in Java
- What is the difference between VAR and DYNAMIC keywords in C#?
- What is the difference between keywords const and readonly in C#?
- What is the difference between Super Computers and Embedded Computers?
- Super and Self Keywords in Rust Programming
- What is the difference between public, static and void keywords in C#?
- Explain the difference between const and readonly keywords in C#
- Difference between Super Key and Candidate key

Advertisements