Object Oriented Programming
Difference Between this and super Keywords And this() and super() Calls In Java?
Clear your basic doubt on this and super keywords Java programming.
In this article, I’m going to explain the difference between this and the super keyword. Also, I’ll be explaining this and super method calls. For most of the beginner/intermediate level Java interviews, interviewers ask this question. By reading this article you will be able to understand the concept and different usage of this and super keywords.
Let’s begin with the basic definition of these keywords …
this VS super
keyword :
The this
keyword is used to access or call current class members(variables, methods or constructors). This keyword is required when we have parameters that have the same names for instance variables or fields.
The super keyword is used to access or call parent class members(variables or methods).
Note: We can use both keywords anywhere in a class but not in a static area(static blocks or static methods). If we use these keywords in a static area then we’ll get a compile-time error.