which of the keyword is used to prevent content of a variable from being modied
Share
which of the keyword is used to prevent content of a variable from being modied
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Answer:
final is the keyword
Final keyword is used to prevent content of a variable from being modified
Explanation:
Final keyword in java
final keyword is used in Java programming with variables, methods and classes in following context:
1) final variable
2) final method
3) final class
Final variable:
When a variable is declared as final, no one is allowed to change or modified the value of a variable after its initialization.
Example:
public class Main
{
final int val=50; //final variable
void change()
{
val = 67;
}
public static void main(String args[])
{
Main obj=new Main();
obj . change();
}
}
Output
error : cannot assign a value to final variable val
val = 67;
1 error