Scope modifiers

From Rosetta Code
Revision as of 17:57, 10 June 2009 by rosettacode>Mwn3d (Created task with Java)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Task
Scope modifiers
You are encouraged to solve this task according to the task description, using any language you may know.

Most programming languages offer support for subroutines. When execution changes between subroutines, different sets of variables and functions ("scopes") are available to the program. Frequently these sets are defined by the placement of the variable and function declarations ("lexical scoping"). These sets may also be defined by special modifiers to the variable and function declarations.

Show the different scope modifiers available in your language and briefly explain how they change the scope of their variable or function. If your language has no scope modifiers, note it.

Java

<lang java>public //any class may access this member protected //only subclasses of this class and classes in the same package may access this member private //only this class may access this member static //for use with other modifiers //limits this member to one reference for the entire JVM

//adding no modifier allows access to the member by classes in the same package</lang>