The result is 50...how can a private variable in parent class be accessed in the subclass. I understand that getX() is inherited.
posted 5 years ago
Because it isn't accessing a private variable. It's accessing a public method, and that method happens to return (a copy of) the value held by the private variable. This is one of the points of encapsulation - you can expose values when you want, but in a controlled way.