Final keyword in Java with example

Final keyword in Java with example

Here you will know use of Final keyword in Java with example code in java programming.

 

What is Final Keyword in Java?

The final keyword in Java signifies immutability. When applied to a variable, method, or class, it indicates that the entity cannot be altered or overridden after initialization or declaration.

 

Use of Final Keyword in Java

In Java, the final keyword serves multiple purposes, each providing a different level of immutability and restriction:

 

final variables

When a variable is declared using the final keyword, it becomes a constant and cannot be modified. The variable declared with the final keyword enables just one assignment; once assigned a value, it cannot be changed again.

final variable example

 

 

final methods

When a method is defined using the final keyword, it cannot be overridden. The final method extends to the child class, but the child class cannot override or redefine it. It must be used as implemented in the parent class.

final methods example

 

 

final class

When a class is defined using the final keyword, no other class can extend it.

final class example

 

 

 

Check out our other Java Programming Examples

 

 

 

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top