What should you do with data fields of your class that represent attributes of a
ID: 3815584 • Letter: W
Question
What should you do with data fields of your class that represent attributes of a real world object ?
Make them all public always
B - Always make them private, provide accessors and/or mutators depending on Use cases that access those objects
Just never make them public and never provided accessors and mutators ever.
Make them private, provide accessors and/or mutators depending on need, BUT move them to public if needed
A -Make them all public always
B - Always make them private, provide accessors and/or mutators depending on Use cases that access those objects
C -Just never make them public and never provided accessors and mutators ever.
D-Make them private, provide accessors and/or mutators depending on need, BUT move them to public if needed
Explanation / Answer
Answer:
B)Always make them private, provide accessors and/or mutators depending on Use cases that access those objects
Explanation:As attributes are real world object we should always provide setters and getters for that as they are designed for that only and we should not allow to access the attributes directly hence make them private.
Note:Please do ask in case of any doubt,Thanks.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.