Final Parameter /Argument Variable

18 January 2012 By Nithya Vasudevan 165 views No Comment
0 Flares Twitter 0 Facebook 0 Google+ 0 0 Flares ×
  • 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));
	}
}