Skip to content
Sharp

Core Java · interview question

Consider the following code snippet. What will be the output when 'new Product().display();' is executed?

Multiple choiceHardchapter-5-curatedpremiumcore-javacode-reading-with-related-types
java
class Item { void display() { System.out.println("Item display"); } }
class Product extends Item { void display() { System.out.println("Product display"); } }
Choose one answer
Answer and explanation

Correct answer

A. Product display

Why

The 'display' method in 'Product' is not overridden and will call the method from 'Item', resulting in 'Product display'.

Test yourself on Core Java

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

Start free test
All Core Java questions →