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.
Its not possible to access a protected instance variable in another package using the upreclass object. For e.g in the foll code line 3 gives Compiler ERROR. But why do not the lines 2 and 3 give any compiler error
protected members when used by subclasses in different packages, should be accessed through inheritence only. there is no other way to access protected members in different package.
that's why line 3 gives error.
But why do not the lines 2 and 3 give any compiler error
I guess you meant line 1 and 2.
Here you are accessing a static member which can be accessed by either class name or class reference irrespective of package provided class is public.
The line 3 is only making trouble. Because, It's accessing the protected member of Class of different package. For a subclass outside the package, the protected member can be accessed only through inheritance.
In line 1, The compiler will changed that line after compiling to as line 2. And here static is dominating.......
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|