Skip to content
Sharp

Object-oriented programming · interview question

Which of the following scenarios demonstrates a poor use of inheritance?

Multiple choiceMediumchapter-5-curatedpremiumoopcomposition-vs-inheritance
Choose one answer
Answer and explanation

Correct answer

B. A 'Square' class inheriting from a 'Rectangle' class.

Why

A 'Square' inheriting from a 'Rectangle' may seem logical, but it violates the Liskov Substitution Principle, as a square has constraints that a rectangle does not.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →