Up: Member Keywords [Contents]
3.1 Access Modifiers
Access modifiers, when provided in keywords, alter the interface into which the definition of member name is placed. There are three interfaces, or levels of visibility, that dictate the context from which a member may be accessed, listed here from the most permissive to the least:
- public
Accessible outside of C or any instance of C (e.g. ‘foo.publicProp’). Inherited by subtypes of C.
- protected
Not accessible outside of C or an instance of C (e.g. ‘this.protectedProp’ within context of C). Inherited by subtypes of C.
- private
Not accessible outside of C or any instance of C. Not inherited by subtypes of C.
Keyword | Description |
---|---|
public | Places member name in public interface (accessible outside of C
or instance of C; accessible by subtypes). Implied if no other access
modifier is provided (but see private ); |
protected | Places member name in protected interface (accessible only within C or instance of C; accessible by subtypes). |
private | Places member name in private interface (accessible only within C or instance of C; not accessible by subtypes); implicit if the member name is prefixed with an underscore, unless another access modifier is explicitly provided. |
Access modifiers have the following properties:
- Only one access modifier may appear in keywords for any given name.
- If no access modifier is provided in keywords for any member
name, member name is implicitly
public
, unless the member name is prefixed with an underscore, in which case it is implicitlyprivate
.
• Discussion: | Uses and rationale | |
• Example: | Demonstrating access modifiers |
Up: Member Keywords [Contents]