| Author |
Protected VS default restiction level
|
Rui Leal
Greenhorn
Joined: Dec 23, 2010
Posts: 2
|
|
Can somebody please explain me why is PROTECTED considered to be more restrictive than DEFAULT?
I think it should be the other way around. Let me explain:
DEFAULT:
member visible to other classes in the same package
PROTECTED:
member visible to other classes in the same package
+
member visible to subclasses outside the package (through inheritance)
That means that in the same conditions:
"Number of classes that can access PROTECTED member" > "Number of classes that can access DEFAULT member"
by this we can say that DEFAULT restricts the access to a smaller group of classes than PROTECTED does ---> DEFAULT is being more restrictive!
What am I missing to understand then?
Thanks
|
 |
W. Joe Smith
Ranch Hand
Joined: Feb 10, 2009
Posts: 710
|
|
I didn't think protected was considered more restrictive. I thought the order was (from least restrictive to most):
Public
Protected
Default
Private
|
SCJA
When I die, I want people to look at me and say "Yeah, he might have been crazy, but that was one zarkin frood that knew where his towel was."
|
 |
Diana Sule
Greenhorn
Joined: Nov 08, 2010
Posts: 21
|
|
Hi Rui,
I agree that what you and Joe said is correct.
Protected is definitely less restrictive than default is.
|
OCPJCP 6.0 | OCPJWCD 5 | SpringSource Certified Spring Professional - Spring 3.0
|
 |
Rui Leal
Greenhorn
Joined: Dec 23, 2010
Posts: 2
|
|
You're both right. Default is in fact more restrictive than protected.
I read somewhere that stated (erroneously) that protected was more restrictive than default... damn it!
Well, that makes both of you and my intuition right
Thanks
|
 |
Diana Sule
Greenhorn
Joined: Nov 08, 2010
Posts: 21
|
|
|
 |
 |
|
|
subject: Protected VS default restiction level
|
|
|