final keyword in java

Writing final classes

Declaring an entire class final is allowed in java.If a class is declared as final can’t be subclassed. It is a very useful for immutable classes such as String class in java.

Writing final methods

You can use final keyword in a method declaration to indicate that the method can’t be overriddden by subclasses and it is critical to consistent state of th object and one can’t change its behavior. Object class have few final methods that you can’t override in your subclass.

Writing final data fields

Declaring a final data field indicates that variable holds a constant value that can’t be changed. For example value of a PI in Math class.

Writing final parameter

A formal parameter can be declared as fina, also known as blank final variable which means it is blank until a value is assigned to it and then value in the variable can’t be changed during the life time of the variable. For example :