Protected member
A protected member is a class attribute or method accessible within its defining class and, subject to language rules, within subclasses or other related contexts.
Essential TypeScript 5, Third Edition
An access control keyword specifies which code can access a class member or other program element.
- How it is used
- Lets subclasses use inherited properties while restricting direct access from other code.
- How deep it goes
- Defines the access rule and applies it to collection properties, while warning that enforcement stops at compilation.
- Examples
- Shows a protected todo-item map used for JSON persistence and a protected array used by a searchable generic collection.
- What you can do after
- Apply it via TypeScript to share class members with subclasses without declaring them public.
Read how Essential TypeScript 5, Third Edition explains protected member →
Python How-To
Protected access is an access level in which a class attribute or method is available to the defining class and its subclasses but not external code.
- How it is used
- Uses a naming convention to communicate which class members belong to implementation details rather than the public interface.
- How deep it goes
- Defines protected access, demonstrates subclass inheritance, and stops short of formal enforcement because Python has no protected keyword.
- Examples
- Uses Task note formatting, Employee vacation requests, Supervisor inheritance, and a protected _urgency backing attribute.
- What you can do after
- Apply it via Python's single-underscore convention to signal subclass-accessible implementation members and shape clearer class interfaces.
100 C++ Mistakes and How to Avoid Them
A protected member is a class member accessible from the class and its derived classes, subject to C++ access rules, but not generally from unrelated client code.
- How it is used
- Controls derived-class access to base-class members while keeping unrelated client code from accessing them.
- How deep it goes
- Explains how protected data can break a class invariant and recommends private state with accessors, without detailing all access rules.
- Examples
- Shows a Student class setting its Person base’s protected age to a negative value, then contrasts private state and validated mutation.
- What you can do after
- Evaluate inheritance designs and replace vulnerable protected state with private data guarded by accessors and mutators.
Read how 100 C++ Mistakes and How to Avoid Them explains protected member →
Kotlin in Action, 2E
The protected modifier restricts access to a declaration to its containing class and subclasses in Kotlin.
- How it is used
- Restricts class-member access to the declaring class and subclasses while preventing same-package access.
- How deep it goes
- Defines the visibility rule, demonstrates an extension-function failure, and contrasts Kotlin with Java package behavior.
- Examples
- Uses TalkativeButton, its protected whisper function, a subclass call, and an extension-function access error.
- What you can do after
- Apply it via Kotlin visibility modifiers to expose implementation details to subclasses while blocking unrelated callers.
Also covered in
What to know first
- inheritanceInheritance is a mechanism in which a derived type or descendant element receives properties or behavior from a parent, subject to rules that may allow specialization or overriding.
- encapsulationEncapsulation is a software design principle that contains data and implementation details behind a controlled interface, restricting direct access to internal state.
- classA class is a programming-language construct that defines a type’s structure and behavior and provides a basis for creating or representing objects.
- attributeAn attribute is a named property or piece of information associated with an entity, object, or structured data item.
Related concepts
- private membercontrasts with · A private member is a program element whose direct access is restricted to its defining class, module, file, or other language-defined scope.
- invariantcontrasts with · An invariant is a condition or property that must remain true across the specified valid states, operations, or transformations of a system or computation.
- encapsulationimplements · Encapsulation is a software design principle that contains data and implementation details behind a controlled interface, restricting direct access to internal state.
- inheritanceused by · Inheritance is a mechanism in which a derived type or descendant element receives properties or behavior from a parent, subject to rules that may allow specialization or overriding.
- instance variableproduces · An instance variable is data associated with a particular object instance, rather than data shared at the class or type level.
- leading underscore conventionconfigured by · The leading underscore convention prefixes an identifier with an underscore to signal intended internal or non-public use without enforcing access restrictions.
Questions about protected member
What is protected member?
A protected member is a class attribute or method accessible within its defining class and, subject to language rules, within subclasses or other related contexts.
Which Manning books explain protected member?
Essential TypeScript 5, Third Edition, Python How-To, 100 C++ Mistakes and How to Avoid Them and Kotlin in Action, 2E.
What should I know before learning protected member?
Manning books that teach protected member usually introduce inheritance, encapsulation, class and attribute first.
What is the difference between protected member and private member?
A protected member is a class attribute or method accessible within its defining class and, subject to language rules, within subclasses or other related contexts. A private member is a program element whose direct access is restricted to its defining class, module, file, or other language-defined scope.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.



