Skip to content
Sharp

Core Java · interview question

Why might using the 'instanceof' operator in a method implementation be considered a bad practice?

Multiple choiceHardchapter-5-curatedpremiumcore-javacode-reading-with-related-types
Choose one answer
Answer and explanation

Correct answer

B. It violates the Open/Closed Principle.

Why

Using 'instanceof' can violate the Open/Closed Principle by creating a method that requires modification when new classes are added, thus reducing flexibility and increasing maintenance.

Test yourself on Core Java

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

Start free test
All Core Java questions →