> code example:
>
[quoted text clipped - 16 lines]
>
> why I can't acces methodInB over reference?
Because the method has access modifier protected. Which means it can be
called from inside the class itself and from any class inside the same
package. Because A is in another package than B, it cannot call the
method inside B.
However it can call the method inside itself.

Signature
Klingon function calls do not have 'parameters' - they have 'arguments'
- and they always in them.
man4*.* - 19 Nov 2006 00:41 GMT
> Because the method has access modifier protected. Which means it can be
> called from inside the class itself and from any class inside the same
> package. Because A is in another package than B, it cannot call the
If I follow your definition of protected, then please describe me
default modifier...you say "..and form any class inside the same
package.." ?? such is definition of default modifier? or isn't?
> method inside B.
> However it can call the method inside itself.
I do not understand why I can't access to the method over
reference when I see the class and use protecded modifier which
allow to access methods in class which is in diferent package...
or did I understand wrong protected modifier?
> code example:
>
[quoted text clipped - 9 lines]
> public class A extends B {
> public A {
I think maybe you mean something like "public A() {"
> B newObject = new B();
> newObject.methodInB(); //won't compile
[quoted text clipped - 3 lines]
>
> why I can't acces methodInB over reference?
Because you are trying to access the methodInB belonging an actual B,
not an A:
JLS Section 6.6.2 Details on protected Access
"A protected member or constructor 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."
http://java.sun.com/docs/books/jls/second_edition/html/names.doc.html#62587
The plain methodInB call accesses the method methodInB for an A instance
from code responsible for implementation of class A objects, so it is
fine. On the other hand, the newObject.methodInB call attempts to access
the methodInB in a B object, from code that is not responsible for the
implementation of class B.
Patricia
man4*.* - 19 Nov 2006 08:46 GMT
> The plain methodInB call accesses the method methodInB for an A instance
> from code responsible for implementation of class A objects, so it is
> fine. On the other hand, the newObject.methodInB call attempts to access
> the methodInB in a B object, from code that is not responsible for the
> implementation of class B.
As always, your's explanations are amazing and so simple... :-))
Thank, thank you!