Link to home
Start Free TrialLog in
Avatar of kellyputty
kellyputty

asked on

Java class visibility

With regards to the following statement:
Normal (non-inner) classes cannot be made private or protected; they may only be given public or package access.

1)Is this because otherwise no other classes could be derived from it? Are there other reasons?

2) I thought "protected" meant only package access???
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kellyputty
kellyputty

ASKER

thanx
:-)
1. There is not point in making a non-inner class private. If there was a non-inner private class it means that the class can be used only by itself and none other. No use of a such an isolated self service class.

2. Protected means access within the package and also by sub-classes. Protected is primarily for inheritence. So it makes sense to have members of a class as protected not the class itself.

here is the accessor hierarchy in Java

Private - within the class
Package - within the package
Protected - within package and sub-classess
Public - every where
thanx.