📢 Too many exams? Don’t know which one suits you best? Book Your Free Expert 👉 call Now!


    Question

    In a language like C++, if a member variable is declared

    protected, it means:
    A It can be accessed from anywhere in the program. Correct Answer Incorrect Answer
    B It can only be accessed from within the class itself. Correct Answer Incorrect Answer
    C It can be accessed from within the class and by derived classes. Correct Answer Incorrect Answer
    D It can only be accessed by friend functions. Correct Answer Incorrect Answer
    E It cannot be accessed at all. Correct Answer Incorrect Answer

    Solution

    The protected access modifier allows members to be accessed by methods within the class itself and by methods within any class that inherits from it (derived classes). It provides a level of access between private (most restrictive) and public (least restrictive).

    Practice Next
    ask-question