The final is a very important keyword in java, which is used to restrict user. A programmer must not declare a variable or class with the name "Final" in a Java program. We can have final methods, final classes, final data members, final local variables and final parameters.
The final is a very important keyword in java, which is used to restrict user. A programmer must not declare a variable or class with the name "Final" in a Java program. We can have final methods, final classes, final data members, final local variables and final parameters.The final is a very important keyword in java, which is used to restrict user. A programmer must not declare a variable or class with the name "Final" in a Java program. We can have final methods, final classes, final data members, final local variables and final parameters.
When an array is declared as final, the state of the object stored in the array can be modified. It must be made immutable so that modifcations are not made.
The final keyword can be applied to:
Syntax of final class:-
final class test { //body of class // final class }
syntax of final variable:-
class test1 { final int=20;//final variable }
Syntax of final method
class test3 { final void run(){// final method }
Note:
Exampleof final jeyword in Java:
public class FinalExample { public static void main(String[] args) { int variable=10; System.out.println("Final Variable:"+variable); variable=15; } public final void getName() { String finalmethod="value"; System.out.println("finalmethod :"+finalmethod); } }
Output
Ads