ProgrammingModerateWipro · Capgemini pattern

A parent class declares protected void run(). Which overriding declaration in a subclass compiles?

  1. A. private void run()
  2. B. public void run()
  3. C. void run()
  4. D. protected int run()

Correct answer: B. public void run()

An override may keep or widen access but never narrow it: protected can become public, but not package-private or private. Changing the return type from void to int is not a valid override either.

More OOP with C++ and Java questions

Exams that ask this topic