this, super and final in Java: Three Keywords Explained
Clear up three essential Java keywords — this (current object), super (parent class), and final (cannot change) — with simple examples and real usage.
This lesson ties a neat bow on the OOP section by clearing up three small keywords you've seen in passing: this, super, and final. Each is short, each is used constantly in real Java, and together they'll make a lot of code you read from now on instantly clearer. This is the last lesson of Level 2 — nice work getting here. 🎉
The this keyword
this means "the current object" — the specific object whose method is running right now. It has two everyday uses.
1. Telling a field apart from a parameter
You met this with constructors. When a parameter has the same name as a field, this.field means "my own field":
class Person { String name; Person(String name) { this.name = name; // this.name = field · name = parameter } }
2. Calling another constructor in the same class
this(...) lets one constructor call another, so you don't repeat setup code:
class Person { String name; int age; Person(String name) { this(name, 18); // call the other constructor with a default age } Person(String name, int age) { this.name = name; this.age = age; } }
The super keyword
If this is "the current object," super is "the parent class." You met it in the inheritance lesson. It also has two main uses.
1. Calling the parent's constructor
super(...) runs the parent's constructor — and if you write it, it must be the first line of the child constructor:
class Animal { String name; Animal(String name) { this.name = name; } } class Dog extends Animal { Dog(String name) { super(name); // run Animal's constructor first } }
2. Calling the parent's version of a method
@Override void makeSound() { super.makeSound(); // do the parent's version... System.out.println("...and then bark."); // ...then add extra }
The final keyword
final means "this cannot be changed." It works on three different things:
final on a… |
Means |
|---|---|
| variable | Its value can't be reassigned — a constant |
| method | Can't be overridden by a subclass |
| class | Can't be extended (no subclasses) |
final double PI = 3.14159; PI = 3.2; // ✗ ERROR — a final variable can't be reassigned
A very common use is constants — values that should never change. The convention is to name them in ALL_CAPS, often with static final together: public static final int MAX_USERS = 100;. You'll see this pattern everywhere in real code (String itself is a final class — which is part of why strings are immutable, as we saw back in Lesson 11).
These three keywords are tiny but they show up on nearly every page of professional Java. In this project's code, final is used constantly for fields that get set once and never change (it's a big part of writing safe, predictable classes), and this/super appear in almost every constructor. Learning to read them fluently is a real step toward reading real-world Java comfortably.
Key takeaways
this= the current object; use it for field-vs-parameter clarity and to call another constructor.super= the parent class; call its constructor (super(...), first line) or its methods.final= can't change: a constant variable, a non-overridable method, or a non-extendable class.- Constants are typically
static finalin ALL_CAPS.
← Previous: Lesson 18 — Packages & static
Next: Lesson 20 — Exception Handling in Java →
↑ Back to the full Java course roadmap