Final variable in java

A Final variable in java is declared with final keyword. It can represent a member variable or local variable. The final variables represents the constants in java and normally declared with static keyword. As final variables are constants that’s why they are initialised at the time of declaration and can’t be reassigned.


class FinalVariableTest{
	//final variable
	final String website = "";
	public void show(){
		//error because value of final variable can't be change.
		website = "";
		System.out.println("website = " + website);
public class Main {
	public static void main(String args[]){
		//creating object of FinalVariableTest Class
		FinalVariableTest obj = new FinalVariableTest();
		//method call;

Output error: cannot assign a value to final variable website
		website = "";
1 error

Java interview questions on final keyword

Please follow and like us:
Content Protection by