Skip to content
Sharp

Core Java · interview question

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

Multiple choiceMediumchapter-5-curatedpremiumcore-javacode-reading-with-related-types
java
abstract class User {
    abstract String getDiscount();
}

class Customer extends User {
    @Override
    String getDiscount() {
        return "10%";
    }
}
Choose one answer
Answer and explanation

Correct answer

C. 10%

Why

In this scenario, the method 'getDiscount()' overrides the method from the superclass 'User'. The 'Customer' class's 'getDiscount()' method is invoked, returning '10%'. This demonstrates method overriding.

Test yourself on Core Java

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

Start free test
All Core Java questions →