Example & Tutorial understanding programming in easy ways.

11.What is final variable and Use of final variable

This section explains the use of final keyword with various different aspects. You can define final variables, final methods and final class by using final keyword in Java. It also describes What is early and later binding.

In Java we can use final keyword with variable, method and class, And each of this combination has certain meaning to it.

When you precede variable declaration with final means that once the value assigned to that variable, It cann't be changed.
In other words, final variable behaves as constant through out your application.
For example, if you assign 10 to the int variable y, then y is going to stay 10, forever So that's straightforward for primitives.

For example,


class FinalKeywordExample {

public static final float PI = 3.14f;

public static void main(String[] args) {

// PI value can't be changed,

// Throws compile time error : final field can't be changed

// PI = 3.141f;

System.out.println("Value of PI = " + PI);




Read More →
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!