Hackforge Academy

Category: java

final keyword

Published on 18 Feb 2026

Explanation

final is a keyword in Java used to restrict modification. It can be applied to variables, methods, and classes.

Code:

final int x = 10;

Explanation

A final variable cannot be reassigned once it is initialized.

Code:

final int number = 100;
// number = 200; // Compilation Error

Explanation

A final method cannot be overridden by a subclass.

Code:

class Parent {
    final void display() {
        System.out.println("Final Method");
    }
}

class Child extends Parent {
    // void display() {} // Error
}

Explanation

A final class cannot be extended by another class.

Code:

final class Animal {
}

// class Dog extends Animal {} // Error

πŸš€ Learn Spring Boot with real-world projects

πŸ’‘ Build REST APIs step by step

🧠 Improve backend development skills

🎯 Get career-ready practical training

Join Our Free WhatsApp Community

Direct access to niche-specific mentors and peers on WhatsApp.

🐍

Python Community

Discuss Django, FastAPI, AI integration, and automation scripts with 15k+ developers.

Join Python Community
βš›οΈ

React Community

Master Next.js, Framer Motion, and State Management. Share your latest UI components.

Join React Community
β˜•

Java Community

Deep dives into Spring Boot, Microservices architecture, and high-performance backend ops.

Join Java Community