Styrow.dev
Question 50 of 247
Java Topic: General medium

How do you prevent a method from being overridden?

Question

How do you prevent a method from being overridden?

Answer

To prevent a specific method from being overridden in a subclass, use the final modifier on the method declaration, which means “this is the final implementation of this method”, the end of its inheritance hierarchy.

public final void exampleMethod() { // Method statements }