Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Scope (computer science)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Java === [[Java (programming language)|Java]] is lexically scoped. A Java class has several kinds of variables:<ref>{{cite web|url=https://docs.oracle.com/javase/tutorial/java/javaOO/variables.html|title=Declaring Member Variables (The Java Tutorials > Learning the Java Language > Classes and Objects)|website=docs.oracle.com|access-date=19 March 2018}}</ref> ; Local variables: are defined inside a method, or a particular block. These variables are local to where they were defined and lower levels. For example, a loop inside a method can use that method's local variables, but not the other way around. The loop's variables (local to that loop) are destroyed as soon as the loop ends. ; Member variables: also called ''fields'' are variables declared within the class, outside of any method. By default, these variables are available for all methods within that class and also for all classes in the package. ; Parameters: are variables in method declarations. In general, a set of brackets defines a particular scope, but variables at top level within a class can differ in their behavior depending on the modifier keywords used in their definition. The following table shows the access to members permitted by each modifier.<ref>{{cite web|url=https://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html|title=Controlling Access to Members of a Class (The Java Tutorials > Learning the Java Language > Classes and Objects)|website=docs.oracle.com|access-date=19 March 2018}}</ref> {| class="wikitable" |- ! Modifier !! Class !! Package !! Subclass !! World |- | public || {{yes}} || {{yes}} || {{yes}} || {{Yes}} |- | protected || {{yes}} || {{yes}} || {{yes}} || {{no}} |- | (no modifier) || {{yes}} || {{yes}} || {{no}} || {{no}} |- | private || {{yes}} || {{no}} || {{no}} || {{no}} |}
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)