---
title: "Explain the use of final keyword in variable, method and class."  
description: "Explain the use of final keyword in variable, method and class."  
author: "Mukul Goenka"  
published: 2021-11-19  
canonical: https://www.mindstick.com/interview/33837/explain-the-use-of-final-keyword-in-variable-method-and-class  
category: "java"  
tags: ["c#", "java", "programming language"]  
reading_time: 2 minutes  

---

# Explain the use of final keyword in variable, method and class.

In Java, the **final** keyword is used as **defining something as constant /final** and represents the non-access modifier.\

## final variable

- When a variable is declared as final in Java, the value can’t be modified once it has been assigned.
- If any value has not been assigned to that variable, then it can be assigned only by the constructor of the class.

## final method

- A method declared as final cannot be overridden by its children's classes.
- A constructor cannot be marked as final because whenever a class is inherited, the constructors are not inherited. Hence, marking it final doesn't make sense. Java throws compilation error saying - modifier final not allowed here

## final class

- No classes can be inherited from the class declared as final. But that final class can extend other classes for its usage.

## Answers

### Answer by Mukul Goenka

In Java, the **final** keyword is used as **defining something as constant /final** and represents the non-access modifier.\

## final variable

- When a variable is declared as final in Java, the value can’t be modified once it has been assigned.
- If any value has not been assigned to that variable, then it can be assigned only by the constructor of the class.

## final method

- A method declared as final cannot be overridden by its children's classes.
- A constructor cannot be marked as final because whenever a class is inherited, the constructors are not inherited. Hence, marking it final doesn't make sense. Java throws compilation error saying - modifier final not allowed here

## final class

- No classes can be inherited from the class declared as final. But that final class can extend other classes for its usage.


---

Original Source: https://www.mindstick.com/interview/33837/explain-the-use-of-final-keyword-in-variable-method-and-class

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
