Do subclasses inherit private fields?

This is an interview question.

Does subclasses inherit private
fields?

I answered “No”, because we can’t access them using the “normal OOP way”. But the interviewer thinks that they are inherited, because we can access such fields indirectly or using reflection and they still exist in the object.

After I came back, I found the following quote in the javadoc:

Private Members in a Superclass

A
subclass does not inherit the private
members of its parent class.

Do you know any arguments for the interviewer’s opinion?

20 Answers
20

Leave a Comment