File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Protected and Private Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Protected and Private" Watch "Protected and Private" New topic

Protected and Private

Conrad Kirby
Ranch Hand

Joined: Jun 17, 2001
Posts: 178
What is the difference between protected and private? Can you read the values of a protected class variable, but not write to it? Or am i completely off track.
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Conrad,
Protected: Can be seen (and used) by the class and any subclasses.
Private: Can only be seen by the class.
The accessor modifiers apply the restrictions to reading and writing. Either you see it and can do anything or you don't and can't!
Conrad Kirby
Ranch Hand

Joined: Jun 17, 2001
Posts: 178
Well thankee kindly! I'll just mosey on back to work!
I agree. Here's the link:
subject: Protected and Private
It's not a secret anymore!