1

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.

Jeena
  • 11
  • 2

3 Answers3

1

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.

Marko Topolnik
  • 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
0

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.

Aniket Thakur
  • 66,731
  • 38
  • 279
  • 289
0

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.!

Tejas jain
  • 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