Accessing private instance variables of parent from child class?
问题 Let's say we have a class foo which has a private instance variable bar . Now let us have another class, baz , which extends foo . Can non-static methods in baz access foo 's variable bar if there is no accessor method defined in foo ? I'm working in Java, by the way. 回答1: No, not according to the java language specification, 3rd edition: 6.6.8 Example: private Fields, Methods, and Constructors A private class member or constructor is accessible only within the body of the top level class (§7