Skip to content
Sharp

Object-oriented programming · interview question

Consider the following code snippet. Why does this inheritance hierarchy violate good design practices?

Multiple choiceHardchapter-5-curatedpremiumoopinheritance-basics
java
class Vehicle {} class Bicycle extends Vehicle {}
Choose one answer
Answer and explanation

Correct answer

C. The subclass should not extend a class it is not truly a type of.

Why

The code snippet violates the 'is-a' relationship because the subclass is extending a class it is not truly a subtype of. This forces an inappropriate inheritance that can lead to maintenance issues.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →