Can a class be declared as protected?

Asked 7 years ago
Viewed 865 times

1

Can a class be declared as protected?


1 Answer


0

No, a class can't be declared as protected. Because protected access modifier can't be applied to class and interfaces. You can declare inner and nested classes as private or protected. In Java you can declare protected Methods and fields, however, methods and fields in an interface cannot be declared protected. Here is one of the big reason for why we can't declare the class using protected access modifier because the access modifier for outer level classes defines their visibility in relation to other assemblies. In Java, only two valid declarations for a class at the namespace level, "Public" and "Internal.

Hope it's informative for you...

answered 7 years ago by Hemant Patel

Your Answer