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%|