• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Private variable accessible in inherited method called using child object

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

Thanks in advance....
 
Marshal
Posts: 76802
366
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

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.
 
We're all out of roofs. But we still have tiny ads:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic