Which option is false about the final keyword?
- A final method cannot be overridden in its subclasses.
- A final class cannot be extended.
- A final class cannot extend other classes.
- A final method can be inherited.
Answer
- A 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).
Comments
Post a Comment