Skip to content
Sharp

Object-oriented programming · interview question

Consider a class with a method public void display() {}. Which of the following is a valid override in a subclass?

Multiple choiceMediumchapter-5-curatedpremiumoopmethod-overriding
Choose one answer
Answer and explanation

Correct answer

B. Public void display()

Why

The overridden method must have the same signature, including the return type. It can only have the same or more accessible visibility, so 'public void display()' is valid.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →