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


    Question

    What are "getter" and "setter" methods primarily used

    for in the context of encapsulation?
    A To define abstract behavior. Correct Answer Incorrect Answer
    B To allow direct access to private fields. Correct Answer Incorrect Answer
    C To provide controlled access to private fields. Correct Answer Incorrect Answer
    D To implement polymorphism. Correct Answer Incorrect Answer
    E To create new instances of a class. Correct Answer Incorrect Answer

    Solution

    Getters (accessors) provide read-only access to private fields, and setters (mutators) provide controlled write access. They act as public interfaces to manipulate the private data, allowing the class to enforce validation rules or other logic before data is read or modified.

    Practice Next
    ask-question