Final Parameter /Argument Variable

  • Final parameter variable can’t be modified within the method i.e.) cannot reassigning a new value to the variable.
  • A method can have any number of final parameters
package com.ibytecode.keywords.finaldemo;

public class FinalParameter {
	public static void main(String[] args) {
		double pi = 3.14;
		double radius = 5;
		circleArea(radius, pi);
	}

	public static void circleArea(double radius, final double PI) {
	/*final argument must keep the same value that the parameter had 
	when it was passed into the method */
		//PI = 4.13; // ERROR
		System.out.println("Area of a Circle: " + 
							(PI * radius * radius));
	}
}

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.