aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Protected VS default restiction level Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Protected VS default restiction level" Watch "Protected VS default restiction level" New topic
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
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Protected VS default restiction level
 
Similar Threads
Protected............
finalize() method
Overloading and overriding the finalize method
can't access finalize() method !!!
trying to understand the reason why...