What is a final parameter in java?


You can pass final variables as the parameters to methods in Java.

A final variable can be explicitly initialized only once. A reference variable declared final can never be reassigned to refer to a different object. However, the data within the object can be changed. So, the state of the object can be changed but not the reference. With variables, the final modifier often is used with static to make the constant a class variable.

Example

Live Demo

public class Test{
   public void sample(final int data){
      System.out.println(data);
   }
   public static void main(String args[]) throws Exception{
      Test t = new Test();
      t.sample(500);
   }
}

Output

500

Updated on: 30-Jul-2019

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements