Fiveable
Fiveable

protected

Definition

In programming, "protected" is an access modifier that grants accessibility to members within subclasses or classes within the same package.

Analogy

Consider a family home with different rooms. While some rooms are accessible to everyone (public), there are certain rooms accessible only to family members (protected). Similarly, when a member is declared as "protected" in programming, it can be accessed by subclasses or classes within the same package.

Related terms

public: In the context of programming, "public" refers to an access modifier that allows a class, method, or variable to be accessed from anywhere in the program.

private: In programming, "private" is an access modifier that restricts the visibility of a class member (method or variable) to only within its own class.

inheritance: The mechanism of creating new classes based on existing ones, allowing for code reuse and adding additional functionality.

"protected" appears in:



© 2024 Fiveable Inc. All rights reserved.

AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.


© 2024 Fiveable Inc. All rights reserved.

AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.