Skip to content
Sharp

Object-oriented programming · interview question

How can you ensure that a class cannot be instantiated in Java?

Multiple choiceHardchapter-2-curatedpremiumoopclasses-and-objects
Choose one answer
Answer and explanation

Correct answer

C. Make the constructor private

Why

Making the constructor private ensures that the class cannot be instantiated from outside the class. This is often used in singleton patterns or utility classes where instantiation is not desired.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →