A protected member can be accessed through inheritance in the subclass , either in the same package or a different package.
But we cannot access a protected member through reference , even in the same package.
Devisri, SCJP 5.0, SCWCD 5.0
"Dream is Not what you see in sleep. Dream is that which never lets you sleep" - Abdul Kalam
Sireesha Mullapudi
Ranch Hand
Joined: Jun 26, 2006
Posts: 74
posted
0
Hi,
In the same package it can be accessed with super class reference.But the subclass-outside-package can't acces it through super class reference.
Just try it with simple code.
Thanks
Burkhard Hassel
Ranch Hand
Joined: Aug 25, 2006
Posts: 1274
posted
0
Objection, your honor!
devisri nanubala wrote:
But we cannot access a protected member through reference , even in the same package.
Sure you can. In the same pack protected members are full visible. Check this, all three classes in the same pack (and file): referenced without inheritance.
Compiles and prints foo! 2.2342
The difference between reference and inheritance shows only in different packages.
Yours, Bu.
all events occur in real time
jibs parap
Ranch Hand
Joined: Dec 07, 2004
Posts: 134
posted
0
Thanks very much for the quick responses..Much appreciated.
I find the word "protected" totally misleading by the way. ...Does not have to do really with this thread but as protected is an access level keyword, one may think, that it protects the access in a way. In a way that it reduces it. But in reality, it widens the access (rather than protecting it), i.e. to inherited members in other packages. Example:
Frog does not compile, because of reduced visibility.
I find it just strange, that "default" is less visible than "protected". But that's only about the naming.