Which of the following statements is/are true regarding the final keyword when used with variables?

  • A final variable can only be initialized once and cannot be changed afterward.
  • A final variable must be initialized at the time of declaration.
  • Final variables are automatically initialized with the default value for their data type.
  • Final variables can be changed in any method of the class.
When the "final" keyword is used with variables in Java, it indicates that the variable's value can only be assigned once, and after that, it cannot be changed. This enforces immutability and is often used for constants. The other options are incorrect. A final variable must be initialized either at the time of declaration or in the constructor of the class. Final variables are not automatically initialized.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *