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.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes About overriding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "About overriding" Watch "About overriding" New topic
Author

About overriding

Mallik Kumar
Greenhorn

Joined: Nov 26, 2011
Posts: 12


The result is 50...how can a private variable in parent class be accessed in the subclass. I understand that getX() is inherited.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4541
    
    8

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.
Mallik Kumar
Greenhorn

Joined: Nov 26, 2011
Posts: 12
Thanks Matthew...
 
Have you checked out Aspose?
 
subject: About overriding
 
It's not a secret anymore!