MCQ: Which option is false about the final keyword?



Which option is false about the final keyword?

  1. final method cannot be overridden in its subclasses.
  2. final class cannot be extended.
  3. final class cannot extend other classes.
  4. final method can be inherited.

Answer

  1. final class cannot extend other classes.

Explanation:

Answer: (c) A final class cannot extend other classes.

Explanation: The final is a reserved keyword in Java that is used to make a variable, method, and class immutable. The important features of the final keyword are:

  • Using the final keyword with a variable makes it constant or immutable. We can't reassign the values of it.
  • A final variable must be a local variable and cannot be used in other classes.
  • Using the final keyword with a method makes it constant, and we can't override it in the subclass.
  • Using the final with a class makes the class constant, and we cannot extend a final class. But a final class can extend other classes.

Hence, the correct answer is an option (c).

Free Spring Boot Tutorial - 5 Hours Full Course


Watch this course on YouTube at Spring Boot Tutorial | Fee 5 Hours Full Course

Comments