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.

KeywordDescription
publicPlaces 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);
protectedPlaces member name in protected interface (accessible only within C or instance of C; accessible by subtypes).
privatePlaces 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.

Table 3.2: Access modifiers

Access modifiers have the following properties:

Discussion: Uses and rationale
Example: Demonstrating access modifiers

Up: Member Keywords [Contents]

Part of the GNU Project

Copyright © 2011, 2012, 2013, 2014, 2015, 2016 Free Software Foundation, Inc.

"GNU Inside!" Page Fold licensed under CC-BY-SA 2.0; incorporates "A Big GNU Head".

The source code of this website is available in the website branch of the Git repository.

Authored by Mike Gerwitz

AltStyle によって変換されたページ (->オリジナル) /