another class in the package can see my protecteds 10
Ron McLeod wrote:That topic was discussed previously in this thread.
Anil Philip wrote:
Ron McLeod wrote:That topic was discussed previously in this thread.
This question is different from the thread you referenced because here we are considering different classes - not different instances of the same class (which is what the other thread discussed).
Anil Philip wrote:I am unable to edit my thread to make a correction
Anil Philip wrote:This question is different from the thread you referenced because here we are considering different classes - not different instances of the same class (which is what the other thread discussed).
The Oracle tutorial wrote:The protected modifier specifies that the member can only be accessed within its own package (as with package-private) and, in addition, by a subclass of its class in another package.
Paul Clapham wrote:
Anil Philip wrote:I am unable to edit my thread to make a correction
Indeed. But would it not be possible for you to reply to this thread with a new post clarifying what you meant to ask?
Mike Simmons wrote:Well, here the question may be more about "why is the rule this way?" rather than "what is the rule?". They could have done things differently, I suppose. But the way it's written now, we can rank the four levels of access from most accessible to least accessible:
public
protected
package
private
Here, each level includes all the powers of the levels below it. Between package and protected, it's easy to say which is "more accessible" (protected) and which is "less accessible" (package).
But, if they had made it so protected allowed access from subclasses, but not access from within the same package (other than within a subclass)... in that case, it would not be possible to say one was more or less accessible than another. Within the same package, package access would be more accessible than protected. And outside the package, protected would be more accessible than package.
Why does this matter? Well to me, first, because I find the nice orderly progression of the first list easy to understand. And more importantly, I think that would be easier for beginners to understand. But also, consider the rules for overriding a method. As it is, we can say that the overriding may be more accessible, but not less accessible. If we didn't allow protected access to include everything in the same package... then the rules for overriding would get more complicated if you were going from package to protected, or protected to package.
Anil Philip wrote:
Mike Simmons wrote:Well, here the question may be more about "why is the rule this way?" rather than "what is the rule?". They could have done things differently, I suppose. But the way it's written now, we can rank the four levels of access from most accessible to least accessible:
public
protected
package
private
Here, each level includes all the powers of the levels below it. Between package and protected, it's easy to say which is "more accessible" (protected) and which is "less accessible" (package).
But, if they had made it so protected allowed access from subclasses, but not access from within the same package (other than within a subclass)... in that case, it would not be possible to say one was more or less accessible than another. Within the same package, package access would be more accessible than protected. And outside the package, protected would be more accessible than package.
Why does this matter? Well to me, first, because I find the nice orderly progression of the first list easy to understand. And more importantly, I think that would be easier for beginners to understand. But also, consider the rules for overriding a method. As it is, we can say that the overriding may be more accessible, but not less accessible. If we didn't allow protected access to include everything in the same package... then the rules for overriding would get more complicated if you were going from package to protected, or protected to package.
I wonder if you may have misunderstood the question.
Anil Philip wrote:I wonder if you may have misunderstood the question.
Paul Clapham wrote:Just to add to those comments about editing: Other people may come by later and be confused by answers to questions which weren't asked, if people go back to edit their earlier posts. So we try to avoid that. We regularly ask people not to do it, and when asked, they usually understand. We may also revert edits if they would result in that kind of confusion. Spelling corrections aren't usually a problem but changing an old post in a significant way is not so good.
Personally if I found that a question that I posted on a forum had been misunderstood, I would add a new post to the thread, saying "Oops, I didn't make that clear, here's what I wanted to say..." or words to that effect.
I used to be able to edit my thread after posting until someone else replied.
I found that I am no longer able to do it even immediately after posting.
It appears that this has been revoked for me.
Anil Philip wrote:Did you remove this edit capability for me - and only for me?
Paul Clapham wrote:
And earlier in this thread you effectively demanded to be allowed to edit an earlier post, when it already had several replies. By now you should realize that we consider that abusive. Please bear that in mind in future.
Paul Clapham wrote:
And earlier in this thread you effectively demanded to be allowed to edit an earlier post, when it already had several replies. By now you should realize that we consider that abusive.
to be allowed to edit an earlier post when it already had several replies"?effectively demanded
".abusive
A lot of people cry when they cut onions. The trick is not to form an emotional bond. This tiny ad told me:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|