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".

Answer from Nithesh Chandra on Stack Overflow
🌐
Scaler
scaler.com › topics › java › this-and-super-keyword-in-java
This and Super Keyword in Java - Scaler Topics
March 8, 2022 - It is used to invoke a method of the immediate parent class. It is used to invoke a constructor of immediate parent class. The super keyword is used to refer to an instance variable of an immediate parent class. ... In the above example, the Child class extends the Parent class.
🌐
GeeksforGeeks
geeksforgeeks.org › java › super-and-this-keywords-in-java
super and this keywords in Java - GeeksforGeeks
June 10, 2024 - Example of this is already shown above where we use this as well as super inside public static void main(String[]args) hence we get Compile Time Error since cannot use them inside static area. We can use this as well as super any number of times in a program. Both are non-static keyword. ... // Java Program to illustrate using this // many number of times class RRR { // instance variable int a = 10; // static variable static int b = 20; void GFG() { // referring current class(i.e, class RR) // instance variable(i.e, a) this.a = 100; System.out.println(a); // referring current class(i.e, class RR) // static variable(i.e, b) this.b = 600; System.out.println(b); // referring current class(i.e, class RR) // instance variable(i.e, a) again this.a = 9000; System.out.println(a); } public static void main(String[] args) { new RRR().GFG(); } }
People also ask

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
🌐
Coding Shuttle
codingshuttle.com › java-programming-handbook › this-vs-super-keyword
this vs super Keyword in Java
April 9, 2025 - class Person { String name; int ... args) { Person p1 = new Person(); p1.display(); } } ... The super keyword is used in inheritance to refer to the parent class....
🌐
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 - Additionally, a local variable with the same name is accessed without any keywords. The "super" keyword in Java allows access to the members (variables and methods) of the parent class.
🌐
W3Schools
w3schools.com › java › ref_keyword_super.asp
Java super Keyword
To understand the super keyword, you should have a basic understanding of Inheritance and Polymorphism. Read more about inheritance (subclasses and superclasses) in our Java Inheritance Tutorial.
🌐
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.
Find elsewhere
🌐
TutorialsPoint
tutorialspoint.com › difference-between-super-and-this-in-java-program
Difference between super() and this() in java Program
With this similarity both these keywords have significant differences between them which are listed as below - ... class A { public int x, y; public A(int x, int y) { this.x = x; this.y = y; } } class B extends A { public int x, y; public B() { this(0, 0); } public B(int x, int y) { super(x ...
🌐
Reddit
reddit.com › r/java › clarification on this(); and super();
r/java on Reddit: Clarification on this(); and super();
April 10, 2012 -

Why can I only have super() or this() in a constructor? Can someone help clarify this for me?

EDIT: Thank you guys, your comments were EXACTLY what I was looking for.

EDIT2: Wow, you guys are crazy helpful. Again, thank you. This makes SOOOOO much more sense now.

Top answer
1 of 5
13
this(); Calls the default constructor of the class you are in. super(); Calls the super-class default constructor of the class you are in. You can use these to simplify your object-construction: public MyObject() { this.var1 = "something"; this.var2 = "something else"; this.var3 = null; } public MyObject(String valueForVar3) { this(); // calls the above constructor this.var3 = valueForVar3; } public MyObject(String valueForVar3, int printCount) { this(valueForVar3); // calls the above constructor for (int i = 0; i < printCount; i++) { System.out.println("var3 is: " + this.var3); } } public static void main(...) { MyObject mo1 = new MyObject(); //mo1.var1 = "something" //mo1.var2 = "something else" //mo1.var3 = null; MyObject mo2 = new MyObject("hello world"); //mo2.var1 = "something" //mo2.var2 = "something else" //mo2.var3 = "hello world"; MyObject mo3 = new MyObject("hello tacos", 50); //mo3.var1 = "something" //mo3.var2 = "something else" //mo3.var3 = "hello tacos"; } Using this pattern, you can add increasingly fine-grained control of your objects. When using inheritance, you can use a super(...) call to call an appropriate super-method. In short, this() and super() are only valid for constructing objects. If you reference this. or super. (without the parentheses,) you are referencing an object. this. being the current class (or superclass, if no matching element exists in the current class). While super. tells the compiler that you are explicitly trying to call something/access something in a super-class. Edit: Official doc on using this. and this() Edit2: Official doc on using super. and super()
2 of 5
5
The class creation protocoll requires all constructors to be called before any other method or code is run. So if the class has a super class, the call to the super class constructor must come first. Alternatively, you can invoke another constructor on the same class.
🌐
Just Academy
justacademy.co › blog-detail › difference-between-this-and-super-in-java
Difference Between This And Super In Java
8) “this” can be used to return the current class instance, while “super” is used to distinguish between methods or fields of the superclass and the current class. 9) When overriding a method in a subclass, the “super” keyword can ...
🌐
Medium
medium.com › @toimrank › this-and-super-keywords-in-java-f84e96f368b2
this and super keywords in java. this keyword is used to access instance… | by Imran Khan | Medium
October 15, 2022 - Below is the code snippet where we are assigning constructor argument value to instance variable using this keyword inside MyClass(int employeeId) constructor. ... Using super we can access the no-arg and parameterized constructors of parent class.
🌐
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.
🌐
Javatpoint
javatpoint.com › this-vs-super-in-java
Difference Between this and super in Java - Javatpoint
Difference Between this and super in Java with java tutorial, features, history, variables, object, programs, operators, oops concept, array, string, map, math, methods, examples etc.
🌐
Java Guides
javaguides.net › 2023 › 11 › difference-between-this-and-super-keyword-in-java.html
Difference between this and super Keyword in Java
March 18, 2024 - The super keyword is used to access methods and constructors of an object's superclass. 1. this is used to refer to the current class's members (variables, methods, constructors). 2. super is used to refer to the parent class's members.
🌐
YouTube
youtube.com › watch
this and super keyword in Java - YouTube
Java this and Java super(): In this video we will see what this keyword and super keyword is in java.This video will give you an example which will make you ...
Published   October 29, 2020
🌐
Educative
educative.io › answers › super-vs-this
super() vs. this()
public class parent extends java.lang.Object{ parent(){ super(); } } In the case that the class has a parameterized constructor: public class parent{ int length; parent(int length){ this.length = length; } } The child class has to pass the ...
🌐
Java67
java67.com › 2013 › 06 › difference-between-this-and-super-keyword-java.html
Difference between this and super keywords in Java | Java67
As shown in this example, we are first forwarding call from no argument constructor of B, to a constructor which accepts one String argument, which further call to super(""), a call to super class, one argument constructor. ... 3) If used them inside constructor than this and super must be first statement, otherwise compiler will complain. Which means you can not call this() and super() from same constructor. Now we know how to use super and this keyword in Java, and comfortable with their intended use.
🌐
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
🌐
ScholarHat
scholarhat.com › home
Super Keyword in Java: A Beginner's Guide to Using Super in Java
September 3, 2025 - Java Full Stack Developer Course . 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.