Explain what are final variable in Java?


Posted On: Jan 12, 2023


In Java programming, a final variable is a variable that can only be assigned a value once. Once a final variable has been assigned a value, it cannot be reassigned or modified. This means that the value of a final variable is constant and cannot be changed throughout the lifetime of the program.

There are two types of final variables in Java:

  • Final instance variables
  • Final static variables

Final variables can be used in a number of ways, such as in defining constants, creating immutable objects, or creating variables that are only set once during the lifetime of a program


final int x=10; //final variable
final static double PI=3.14; //final static variable

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    Core Java Interview Questions

    Explain the significance of class loaders in Bootstrap?

    In order to load the Java Classes into a virtual environment, Classloader are used. A class loader will load key classe..

    Core Java Interview Questions

    What is the difference between JDK, JRE, and JVM?

    It is important to understand the difference between JDK, JRE, and JVM in Java.JVM (Java Virtual Machine) Java..

    Core Java Interview Questions

    What are the various access specifiers in Java?

    Access specifiers in java are the keywords which define the access scope of the function. It can be used before a class..