Skip to content
Sharp

Core Java · interview question

Consider the following classes. What will be the output of 'new PremiumService().getInfo();'?

Multiple choiceHardchapter-5-curatedpremiumcore-javacode-reading-with-related-types
java
class Service { String getInfo() { return "Service Information"; } }
class PremiumService extends Service { @Override String getInfo() { return "Premium Service Information"; } }
Choose one answer
Answer and explanation

Correct answer

D. Premium Service Information

Why

The 'getInfo' method in 'PremiumService' overrides the method from 'Service', so calling 'getInfo' on an instance of 'PremiumService' will execute the overridden method, outputting 'Premium Service Information'.

Test yourself on Core Java

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

Start free test
All Core Java questions →