Lets consider this situation
class Animal {
void eat() {
System.out.println("animal : eat");
}
}
class Dog extends Animal {
void eat() {
System.out.println("dog : eat");
}
void anotherEat() {
super.eat();
}
}
public class Test {
public static void main(String[] args) {
Animal a = new Animal();
a.eat();
Dog d = new Dog();
d.eat();
d.anotherEat();
}
}
The output is going to be
animal : eat
dog : eat
animal : eat
The third line is printing "animal:eat" because we are calling super.eat(). If we called this.eat(), it would have printed as "dog:eat".
GeeksforGeeks
geeksforgeeks.org › java › super-and-this-keywords-in-java
super and this keywords in Java - GeeksforGeeks
June 10, 2024 - In java, super keyword is used to access methods of the parent class while this is used to access methods of the current class.
Scaler
scaler.com › topics › java › this-and-super-keyword-in-java
This and Super Keyword in Java - Scaler Topics
March 8, 2022 - The super keyword can be used to invoke the parent class methods and constructors. It can also be used to access the fields of the parent class. The this keyword is used to represent the current instance of a class. It is used to access the instance variables and invoke current class methods ...
Videos
What is the difference between super & this keyword (Core ...
12:11
#51 This and Super Method in Java - YouTube
Java Constructors || Differences between super(),this() and ...
This and Super keywords with Constructor Examples In Java
09:04
Difference between THIS keyword and SUPER keyword in JAVA | this ...
How does the "this" keyword enhance object-oriented programming in Java?
A. This keyword in Java is essential to object-oriented programming because it provides a reference to the current object. It facilitates self-reference within methods, enables method chaining for fluent interfaces, permits the distinction between instance variables and method parameters, and assists in the invocation of constructors.
upgrad.com
upgrad.com › home › tutorials › software & tech › this and super keyword in java
This and Super Keyword in Java: Differences, Examples & Uses
In static methods, is it possible to use 'this' and 'super'?
A: Static methods do not have access to 'this' and 'super' keywords. The pairing that works is as follows: instance methods can directly access both instance variables and methods, as well as static variables and methods. However, 'this' and 'super', which are inherently tied to object instances, are not available for use within static methods.
upgrad.com
upgrad.com › home › tutorials › software & tech › this and super keyword in java
This and Super Keyword in Java: Differences, Examples & Uses
Can we use the "this" and "super" keywords interchangeably?
A: No, the "this" and "super" keywords serve different purposes. "This" refers to the current object, while "super" references the parent class. Their usage depends on the context and the specific functionality you intend to achieve.
upgrad.com
upgrad.com › home › tutorials › software & tech › this and super keyword in java
This and Super Keyword in Java: Differences, Examples & Uses
Top answer 1 of 9
81
Lets consider this situation
class Animal {
void eat() {
System.out.println("animal : eat");
}
}
class Dog extends Animal {
void eat() {
System.out.println("dog : eat");
}
void anotherEat() {
super.eat();
}
}
public class Test {
public static void main(String[] args) {
Animal a = new Animal();
a.eat();
Dog d = new Dog();
d.eat();
d.anotherEat();
}
}
The output is going to be
animal : eat
dog : eat
animal : eat
The third line is printing "animal:eat" because we are calling super.eat(). If we called this.eat(), it would have printed as "dog:eat".
2 of 9
56
super is used to access methods of the base class while this is used to access methods of the current class.
Extending the notion, if you write super(), it refers to constructor of the base class, and if you write this(), it refers to the constructor of the very class where you are writing this code.
GeeksforGeeks
geeksforgeeks.org › java › difference-super-java
Difference between super() and this() in java - GeeksforGeeks
November 9, 2022 - super and this keyword super() as well as this() keyword both are used to make constructor calls. super() is used to call Base class's constructor(i.e, Parent's class) while this() is used to call the current class's constructor.
Naukri
naukri.com › code360 › library › difference-between-this-and-super-in-java
Java Super vs This Keywords: Usage and Examples
Almost there... just a few more seconds
Upgrad
upgrad.com › home › tutorials › software & tech › this and super keyword in java
This and Super Keyword in Java: Differences, Examples & Uses
September 24, 2024 - The primary purpose of the "this" keyword is to refer to the current object, while the "super" keyword allows access to the members of the parent class. These keywords help resolve naming conflicts, differentiate between instance variables and ...
Scientech Easy
scientecheasy.com › home › blog › difference between super and this keyword in java
Difference between Super and This Keyword in Java - Scientech Easy
April 25, 2025 - If a subclass overrides a method from the superclass and wants to use the superclass’s implementation, we can use ‘super.methodName()’ to explicitly call the superclass method. ... The keyword ‘this’ in Java is a reference variable that refers to the current instance of the class. It is commonly used to differentiate between instance variables and method parameters with the same name.
TutorialsPoint
tutorialspoint.com › difference-between-super-and-this-in-java-program
Difference between super() and this() in java Program
Along with various other keywords Java also provides this and super as special keywords which primarily used to represent current instance of a class and it's super class respectively. With this similarity both these keywords have significant differences between them which are listed as below -
Javatpoint
javatpoint.com › this-vs-super-in-java
Difference Between this and super in Java - Javatpoint
this keyword · Inheritance(IS-A) Aggregation(HAS-A) Method Overloading · Method Overriding in Java · Covariant Return Type · super keyword · Instance Initializer block · final keyword · Runtime Polymorphism · Dynamic Binding · instanceof operator · Abstract class in Java ·
YouTube
youtube.com › telusko
#51 This and Super Method in Java - YouTube
Check out our courses:Enterprise Java Spring Microservices: https://go.telusko.com/enterpriseJavaCoupon: TELUSKO10 (10% Discount)Master Java Spring Develop...
Published January 18, 2023 Views 106K
TutorialsPoint
tutorialspoint.com › Difference-between-super-and-this-in-Java
Difference between super() and this() in Java
class Animal { String name; Animal(String name) { this.name = name; } public void move() { System.out.println("Animals can move"); } public void show() { System.out.println(name); } } class Dog extends Animal { Dog() { //Using this to call current class constructor this("Test"); } Dog(String name) { //Using super to invoke parent constructor super(name); } public void move() { // invokes the super class method super.move(); System.out.println("Dogs can walk and run"); } } public class Tester { public static void main(String args[]) { // Animal reference but Dog object Animal b = new Dog("Tiger"); b.show(); // runs the method in Dog class b.move(); } } ... Difference between Go and Java.
Educative
educative.io › answers › super-vs-this
super() vs. this()
The this keyword is used to access the members of the current class. It can also be used to access the members of the parent class that are accessible from the child class, e.g., inheritance.