ЁЯУв Too many exams? DonтАЩt know which one suits you best? Book Your Free Expert ЁЯСЙ call Now!


    Question

    When designing a class, why is it generally a bad

    practice to make all fields public?
    A It makes the class abstract. Correct Answer Incorrect Answer
    B It violates the principle of encapsulation, leading to potential data corruption and reduced maintainability. Correct Answer Incorrect Answer
    C It prevents the class from being inherited. Correct Answer Incorrect Answer
    D It makes the class static. Correct Answer Incorrect Answer
    E It causes compilation errors. Correct Answer Incorrect Answer

    Solution

    Making all fields public directly exposes the internal state of an object, breaking encapsulation. This allows external code to directly modify the data without any control or validation, making it difficult to maintain data integrity, track changes, and refactor the internal implementation without affecting client code.

    Practice Next
    More IT Operating System Questions
    ask-question