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.
v bobby wrote:Protected Variables in one class is visible through inheritance to other class which is in different package??
why it is not visible while using object of that class. ??
You will have to show code which shows what problem you are having.
Remember that the variables are only visible in blocks of code which have access to them. So let's say you have this:
This class has a protected member which I want to access elsewhere.
This is a child class in a different package who can see and use the variable just fine.
But if I tried to access the variable from some other class through a NumberDisplayer reference, I can't do that:
On line 9 there I am going to get an access exception. Even though NumberDisplayer has access to the variable, and even though NumberDisplayer and Runner are in the same package, I can't access the variable because it belongs to NumberHolder which is in a different package than Runner and because Runner is not a child of NumberHolder. It is the code which does the accessing (in this case Runner#main()) which needs access to the variable, not necessarily the Object through which the code is calling (the NumberDisplayer).