...when a subclass-outside-the-package inherits a protected member, the member is essentially private inside the subclass, such that only the subclass and its subclasses can access it.
Preparing SCJP 1.5
Please, correct me if I'm wrong.
..when a subclass-outside-the-package inherits a protected member, the member is essentially private inside the subclass, such that only the subclass can access it.
Preparing SCJP 1.5
Preparing SCJP 1.5
Originally posted by Jeronimo Sanchez ...when a subclass-outside-the-package inherits a protected member, the member is essentially private inside the subclass, such that only the subclass and its subclasses can access it.
Preparing SCJP 1.5
Originally posted by Jeronimo Sanchez:
Now that I've fixed the source code file... it works!That means, hence, that protected members do not become private in subclasses outside the package where they are declared!!! Which is still an errata, isn't it?
Now I am even more confused![/QB]
We're binary code: a one and a zero<br />You wanted violins and you got Nero
Then, why does the author write "...the (protected) member is essentially private inside the subclass"?
Preparing SCJP 1.5
Originally posted by Jeronimo Sanchez To Naseem:
Of course Test cannot access "i" in your example. It is protected,
Preparing SCJP 1.5
Test1{
protected int i=9;
}
Test2{
public static void main(String args[]){
System.out.println(new Test1().i); // line 1
}
}
Preparing SCJP 1.5
Originally posted by Jeronimo Sanchez:
To Naseem:
To Kevin:
Thanks for your explanation. I see your point, but it makes no sense to say that a member is private for non subclasses, since for non subclasses it doesn't really matter if a class member is protected or private: they cannot access the members in both cases.
Private only differs from protected regarding inheritance: meanwhile protected allows the member to be access through inheritance, private does not. And Naseem and I have demonstrated that protected members got inherited to grandchildren classes outside its package. So it cannot become private. So there's an errata in the book.
Why is so difficult to understand. Am I missing something?
[ July 25, 2006: Message edited by: Jeronimo Sanchez ]
We're binary code: a one and a zero<br />You wanted violins and you got Nero
No! Once the subclass-outside-the package inherits the protected member, that member (as inherited by the subclass) becomes private to any code outside the subclass, with the exception of subclasses of the subclass.
Preparing SCJP 1.5
Preparing SCJP 1.5
We're binary code: a one and a zero<br />You wanted violins and you got Nero
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Preparing SCJP 1.5
Originally posted by Jeronimo Sanchez:
My last thought regarding this subject is: if the secret does not become protected in class C (since class E cannot access it), nor private (since class D inherits the secret)... is it possible to say we have a fifth access control level, yet very specific?
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Preparing SCJP 1.5
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.