ProgrammingHardGATE CS · TCS NQT Prime · Product Company SDE

Why can a private method in a Java superclass never be overridden by a subclass, only unintentionally hidden (i.e. always statically bound)?

  1. A. Private methods are automatically declared final for an unrelated reason
  2. B. Private methods are not inherited or even visible to a subclass; a same-named method the subclass declares is really an entirely separate, unrelated method
  3. C. The JVM cannot resolve any private method call at run time
  4. D. Private methods actually can be properly overridden in Java

Correct answer: B. Private methods are not inherited or even visible to a subclass; a same-named method the subclass declares is really an entirely separate, unrelated method

Because a subclass cannot even see its superclass's private methods, it cannot override them; any identically-named method it defines is simply a distinct method that happens to share a name.

More OOP with C++ and Java questions

Exams that ask this topic