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.
No, not according to the java language specification, 3rd edition:
But regardless of this language restriction, you can access private fields through reflection: