Can a class be declared as protected?

1 votes
160 views
Odilian Gosselin asked 21-Dec-2017 in Technology by Odilian Gosselin

Can a class be declared as protected?

1 Answer

0 votes
Harsh kumar srivastava answered 21-Dec-2017 by Harsh kumar srivastava

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