Skip to content
Sharp

Object-oriented programming · interview question

Given the code snippet, what is the result of calling 'getOrderDetails' on a 'SpecialOrder' object?

Multiple choiceHardchapter-5-curatedpremiumooppolymorphism
java
class Order { String getOrderDetails() { return "Order details from Order"; } }
class SpecialOrder extends Order { String getOrderDetails() { return "Order details from SpecialOrder"; } }
Choose one answer
Answer and explanation

Correct answer

A. Order details from SpecialOrder

Why

Despite 'Order' having its own 'getOrderDetails' method, the 'SpecialOrder' class overrides it. Hence, the overridden method in 'SpecialOrder' is executed, demonstrating polymorphism at runtime.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →