Skip to content
Sharp

Object-oriented programming · interview question

In Java, how can you ensure that a class cannot be subclassed?

Multiple choiceMediumchapter-3-curatedpremiumoopobject-responsibility
Choose one answer
Answer and explanation

Correct answer

D. Declare the class as final

Why

Declaring a class as final prevents it from being subclassed. This is useful when you want to ensure that the implementation details of the class are not altered through inheritance.

Test yourself on Object-oriented programming

A free test with instant, explained results. No account needed.

Start free test
All Object-oriented programming questions →