Types of Final Variable in Java

Final Variable

Before knowing types of final variable you should know What is a Final Variable? Final variable is a variable which  is declared using final keyword before it. For example,

Class Tst
 {
   int final var1 = 10; // var1 is declared as final variable...
}

There are two very important related to Final Variables that are-

1. Final Variable's value never changes.

2. Final variable must be declared during declaration time.

Now, we will discuss about Types of Final variable.
There are following types of final variables-

1. Final Instance Variable
2. Final Static Variable
3. Final Local Variable
4. Final Block Level Variable
5. Final Parameterized Variable

1. Final Instance Variable -  Those variables which are declared as Final Instance i.e. Final                                                 Instance Variable.

2. Final Static Variable -       Those variables which are declared as Final Static i.e. Final                                                     Static Variable.

3. Final Local Variable -        Those variables which are declared as Final Local i.e. Final                                                     Local Variables.
Note-  Final variable may or may not be initialized at declaration time.

4. Final Block Level Variable-  Those variables which are declared as Final block level i.e.                                                 Final Block Level Variable.

5. Final Parameterized Variable-  Those variables which are declared as Final parameter                                                   in method  i.e. known as Final Parameterized  Variable. 
Note-    'final' is the one of the unique access modifier in java ,that can be use inside method or method parameter.

Popular posts from this blog

10 basic Java interview questions with their answers

Internal working of JVM(Java Virtual Machine)

Introduction to java programming language