Final Keyword in Java

Share this on :

Final keyword can be used:
1.With class name 2.With method name 3.With variable name

Uses of final Keyword:
1. To prevent Inheritance: If we want to prevent a class from being inherited then we use final keyword.

2. To prevent Overriding: If we want that method should not be overridden by sub class then we use final keyword..

3. To make the value of variable as constant: If we make the variable final then this will be treated as constant its value remains unchanged.

Share this on :