What does the ‘final’ keyword do in Java?

Java MCQ: What does the ‘final’ keyword do in Java?

a) Prevents method overriding
b) Prevents inheritance
c) Prevents variable reassignment
d) All of the above

Answer:

d) All of the above

Explanation:

The final keyword in Java can be used to prevent method overriding, inheritance, and variable reassignment. When applied to a class, it prevents subclassing; when applied to a method, it prevents overriding; and when applied to a variable, it makes the variable constant.

Understanding the final keyword is crucial for controlling how classes and methods are extended or modified.

Reference links:

https://www.rameshfadatare.com/learn-java-programming/
https://www.javaguides.net/p/java-tutorial-learn-java-programming.html

Leave a Comment

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

Scroll to Top