Easy learning with example program codes

what is final variable in java?

A variable declared with final keyword is known as final variable. It may be member variable or local variable. The final variables are constants in java and they are generally declared with static keyword. As final variables are treated as constants they can’t reassign. They are initialised at the time of declaration.


 * This program is used to show that the value of 
 * final variable can't be change. 
 * @author CodesJava
class Test{
	//final variable
	final int num = 100;
	//method for try to change the value of final variable.
	public void show(){
		//error because value of final variable can't be change.
		num = 200;
		System.out.println("Num = " + num);
public class FinalExample1 {
	public static void main(String args[]){
		//creating object of Test Class
		Test obj = new Test();
		//method call;


Exception in thread “main” java.lang.Error:
Unresolved compilation problem:
The final field Test.num cannot be assigned

Java interview questions on final keyword

Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at


We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on

Copyright © 2019 CodesJava Protection Status SiteMap Reference: Java Wiki