This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Hello guys....Let me post a code sample before asking my question:
Above code works perfectly fine...My concern is how was it possible to execute a method (viz. method0 here) using child class object when the method accessed a private variable 'a' from Parent class? I mean, method0 was inherited by child class AccessTest...and variable a was not as it is private..so I consider it as compiler will see the code for child class as if method0 was pasted in the child class.... so it was like:
If we look at the above code sample alone, we can not see variable a in child class as it was private and hence not inherited....so it should not be visible in the child class's method0...Still how did my program work?
The private field might not be inherited, but the public method is. Because you did not override it, it does exactly the same as in the superclass.
I shall try adding code tags to your post, because it makes it look much better. Parent and method0 are not good names for classes and methods.