Hi! As you presumably know, anythibg declared as private is visible only in the class itself. If you declare them as public, they can be accessed from any class in any package. But if you want things to be accessed also in successors of your class, you declare it private. So 'protected' basicly means: "only me and my subclasses can see this"
Joined: Oct 09, 2003
Yes nanook, i agree protected means only me and my subclasses. But protected behaves as public for classes in same package.I am not convinced that OOPS is satisfied here.
Nanook -- You've already been warned once to change your display name. Please comply or we'll have to close your account. Lekha and Nanook -- You're unfortunately both incorrect in your expectations. "protected" means access from subclasses and from other classes in the same package. Java does not have an access level that means only subclasses. Note that the access levels "nest". Each one opens things up a bit more. There are no access levels that both add new permissions and revoke permissions from a lower level.
private -- one class only.
default -- all classes in a package.
protected -- all classes in a package plus subclasses.
private -- one class only. default -- all classes in a package. protected -- all classes in a package plus subclasses. public -- all classes. That I know is how java deals with access levels. But my problem is If I have to give access only to child classes then i have to have all unrelated classes in seperate package .Is that the only solution.
author and iconoclast