Easy learning with example program codes

what is final parameter in java?

A method parameter declared with final keyword is known as final parameter. Its value can’t be changed.


 * This program is used to show that value of 
 * final parameter can't be changed.
 * @author CodesJava
class Test{
	public void showDouble(final int num){
		//error because value of final parameter can't be changed.
		num = num * 2;
		System.out.println("Num * 2 = " + num);
public class FinalExample7 {
	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 local variable num cannot be assigned. 
It must be blank and not using a compound assignment

Java interview questions on final keyword

Please follow and like us:

Copyright © 2019 CodesJava Protection Status SiteMap Reference: Java Wiki