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


    Question

    Which access modifier is most commonly used to achieve

    data hiding in encapsulation?
    A public Correct Answer Incorrect Answer
    B protected Correct Answer Incorrect Answer
    C private Correct Answer Incorrect Answer
    D default (package-private in Java) Correct Answer Incorrect Answer
    E static Correct Answer Incorrect Answer

    Solution

    The private access modifier restricts access to members (fields or methods) only within the class where they are declared. This effectively hides the internal data from external classes, forcing them to interact with the data through public methods (getters/setters).

    Practice Next
    ask-question