In this example we will show the method to create a final variable in Java.
Source Code
package com.beginner.examples;
public class CreateFinalVariable {
public static void main(String[] args) {
final int i = 3;
i = 7; // will compilate failed
System.out.println(i);
}
}
Output:
error: cannot assign a value to final variable i