Einstein: A problem cannot be solved in the same state of mind in which it was created.
More motivation: http://www.youtube.com/watch?v=_7xfyDjCFqs
implementation of that object
Nikhil Pujari wrote:I know it has something to do with this:
Sun language specification, 6.6.2-
"A Protected member of an object may be accessed from outside the package in which it is declared only by code that is responsible for the implementation of that object."
What does "implementation of that object" mean? I can't seem to connect the dots. Any help will be appreicated.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Nomaan Butt wrote:
implementation of that object
this means you can access a protected member of a class through its own object outside the package. you can't access it through the subclass object of the class which actually has the protected member or field.
According to your example, you can't access show() of ProtectedClass through ExtendsProtectedClass object outside package first. If you need to access
show() in package second you will have to create object of ProtectedClass.
Einstein: A problem cannot be solved in the same state of mind in which it was created.
More motivation: http://www.youtube.com/watch?v=_7xfyDjCFqs
Einstein: A problem cannot be solved in the same state of mind in which it was created.
More motivation: http://www.youtube.com/watch?v=_7xfyDjCFqs
Nikhil Pujari wrote:...This is an exception to the rule that says - Protected members can be accessed by any class in the same package.
The above does not hold if all the four classes are in the same package. In this case, D can access a1.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
It's maybe worth remembering that Class B doesn't inherit a copy of a1, it inherits a1 itself; because a class B is a class A.
However, a1 still belongs to class A, because that's where it is defined; and that is why class D can't access it.
Einstein: A problem cannot be solved in the same state of mind in which it was created.
More motivation: http://www.youtube.com/watch?v=_7xfyDjCFqs
Nikhil Pujari wrote:
Winston Gutkowski wrote:
It's maybe worth remembering that Class B doesn't inherit a copy of a1, it inherits a1 itself; because a class B is a class A.
However, a1 still belongs to class A, because that's where it is defined; and that is why class D can't access it.
Does that mean a1 is shared by objects of class A and class B? I thought an object of class B had a separate a1 than that of class A, and if you modified a1 in an object of class B, then the other one would not be affected.
Consider Paul's rocket mass heater. |