| Visibility | Class scope |
| Gotchas | Links |
| Limiting Scope |
| Java Scope | ||
|---|---|---|
| Scope | Visibility | Purpose |
| published | visible to external users of a Javabean | Javabean properties and methods. There is no way to declare a method published in the Java source. You use a special getXXX/setXXX naming convention and write a separate declaration file. |
| public | visible to all classes | methods and variables of interest to users of the class. |
| protected | visible to classes outside the package that inherit the class, also to all classes in the package. | methods and variables of interests to third parties who may extend your class. |
| default
aka package aka friendly |
visible to all classes of the package. | methods and variables involved in cross-class communication within the package. |
| private | visible only within the class, not by inheritors, not by other classes in the package. | Variables and methods that should not or would not be changed by someone extending the class. Proper functioning of the class depends on them working precisely as written. |
| local | visible only to the block of the method in which the variables were declared. | Temporary working variables. |
| Permitted class scopes | ||||
|---|---|---|---|---|
| Type | public | protected | default | private |
| standalone class | ||||
| top level class | ||||
| inner class | ||||
| static nested class | ||||
| anonymous class | ||||
| local class | ||||
|
|
You can get the freshest copy of this page from: | or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror) |
| http://mindprod.com/jgloss/scope.html | J:\mindprod\jgloss\scope.html | |
![]() | Please email your feedback for publication,
letters to the editor, errors, omissions, typos, formatting errors, ambiguities, unclear wording,
broken/redirected link reports, suggestions to improve this page or comments to
Roedy Green :
| |
| Canadian Mind Products | ||
| mindprod.com IP:[65.110.21.43] | ||
| view Blog | Your face IP:[38.107.179.211] | |
| Feedback | You are visitor number 106,980. | |