Last updated 2004-06-28 by Roedy
Green ©1996-2004 Canadian Mind Products
Java definitions: 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
You are here : home : Java Glossary : S words : 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. |
There is no scope that will allow derived classes to see a method or variable, but hide it from the rest of the package. There is no scope that will allow derived classes within a package to see a method or variable, but hide it from the rest of the package.
There are five benefits to limiting the scope of indexing variables to the loop block:
Java has one surprise scope rule. You may not redefine a local variable inside a block nested within its scope. Local variables may hide instance variables however.
| Permitted class scopes | ||||
|---|---|---|---|---|
| Type | public | protected | default | private |
| standalone class | Y | N | Y | N |
| outer class in same file as another public class | N | N | Y | N |
| inner class | Y | Y | Y | Y |
| static inner class | Y | Y | Y | Y |
home |
Canadian Mind Products | |||
| mindprod.com IP:[24.87.56.253] | ||||
| Your IP:[80.134.30.163] | ||||
| You are visitor number 4240. | ||||
| Please send errors, omissions and suggestions | ||||
| to improve this page to Roedy Green. | ||||
| You can get a fresh copy of this page from: | or possibly from your local J: drive mirror: | |||
| http://mindprod.com/jgloss/scope.html | J:\mindprod\jgloss\scope.html | |||