While the visibilty of a default modifier comes below that of protected in the heirarcy of modifiers, why is it that a class can be made as default but not as protected.
-
You mean the top level class? – Aniket Thakur Dec 17 '13 at 11:17
-
It's entirely possible to make a class `protected`. Can you explain more clearly what it is that you're trying to where you think you can't? – T.J. Crowder Dec 17 '13 at 11:20
-
The class here I'm speaking of is the class at the package level. – Jeena Dec 17 '13 at 12:08
3 Answers
why is it that a class can be made as default but not as protected?
A more sensible question would be, why does Java tolerate anything but public top-level classes?
The provision to allow package-private top-level classes is already a hack of the earliest versions of Java, improved on and superseded by nested classes, which can be protected
if you want.

- 195,646
- 29
- 319
- 436
-
About package private history: http://programmers.stackexchange.com/a/220109/47845 - that's probably what you are referring to! – assylias Dec 17 '13 at 11:25
-
That's even deeper history than what I have investigated :) Another nugget: Java 1.0 allowed `private protected` with the meaning as `protected` in C. – Marko Topolnik Dec 17 '13 at 11:39
I hope you meant top level class(can only be public or default). Otherwise inner classes can have any modifier.
When we say protected it means that it is accessible from all subclasses of the class enclosing the protected entity(Can be a class).
If outermost class is protected then it defines the very definition of protected modifier.

- 66,731
- 38
- 279
- 289
class can be protected!. i,e inner class can be protected .
class A{
protected class C{
}
}
Protedted comes into picture when we are talking about inheritance (extends). Thats why we cant have anything outside inheritance context as protected.!

- 742
- 7
- 20
-
i am refering to the class at a package level not being able to be made protected. Sorry for the confusion. – Jeena Dec 17 '13 at 11:50