Question
When designing a class, why is it generally a bad practice to make all fields public?
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.
More IT Operating System Questions
- Which of the following real-world applications commonly uses a queue data structure to manage its operations?
- How do you correctly create a new Map object in JavaScript?
- Which cloud service model provides the highest level of control over the underlying infrastructure?
- In AJAX (Asynchronous JavaScript and XML), which of the following properties must be set to true to prevent the browser from waiting for the response befor...
- What is the purpose of version control systems (e.g., Git, SVN)?
- Which of the attributes shown below is a simple attribute?
- fill the blank for 19.
- Which of the following statements about guided transmission media is correct?
- A developer is choosing between an array and a linked list to store a collection of elements. If the primary operations will be frequent insertions and del...
- Why does paging incur memory overhead in operating systems?