ProgrammingHardProduct-company placement · Java

How many of these statements are correct in Java? (i) A subclass object contains storage for its superclass's private fields. (ii) A subclass method can read a superclass's private field directly by name. (iii) A method in a subclass with the same signature as a private superclass method does not override it. (iv) Constructors of a superclass are inherited by its subclasses.

  1. A. 1
  2. B. 2
  3. C. 3
  4. D. 4

Correct answer: B. 2

(i) and (iii) are correct: private state still exists in the object (reachable through inherited public methods), and private methods are invisible so they cannot be overridden. (ii) and (iv) are false: constructors are never inherited.

More OOP with C++ and Java questions

Exams that ask this topic