You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So I came across this thread on StackOverflow which I found interesting. Perhaps someone would like to share their thoughts on the semantics of this question?
TLDR - Subclasses do not inherit private members of their parent class. By that definition, the subclasses themselves do not inherit the private fields of their parent class. However, the objects of subclasses do contain the private fields.
The text was updated successfully, but these errors were encountered:
Confusing as the meaning of "inheriting" fields of their parent class is quite blur to me. I would like to think all subclasses should have the fields of their parent classes since these fields need to be instantiated with every instance of the subclass - object created. However, I think saying that they inherit the private fields is wrong, since I cannot access the field in my subclass if it is private in my parent class(without a getter method).
Thank you for starting this very insightful discussion! My perception of private fields is so that we would not be able to access this field from objects outside of the class, and we access that variable through a method instead (bringing in the concept of immutability). As such, i think that it is important for the subclasses to not inherit these private fields. That being said, they must also be able to access it since it is obviously a subclass of the parent class, thus the fact that they contain the private fields seem understandable.
So I came across this thread on StackOverflow which I found interesting. Perhaps someone would like to share their thoughts on the semantics of this question?
TLDR - Subclasses do not inherit private members of their parent class. By that definition, the subclasses themselves do not inherit the private fields of their parent class. However, the objects of subclasses do contain the private fields.
The text was updated successfully, but these errors were encountered: