C++ | Class and Object | Question 4
Which of the following is true?
All objects of a class share all data members of class
Objects of a class do not share non-static members. Every object has its own copy.
Objects of a class do not share codes of non-static methods, they have their own copy
None of the above
Answer: (B) Explanation:
Every object maintains a copy of non-static data members. For example, let Student be a class with data members as name, year, batch. Every object of student will have its own name, year and batch. On a side note, static data members are shared among objects.
All objects share codes of all methods. For example, every student object uses same logic to find out grades or any other method.Quiz of this Question
Share your thoughts in the comments
Please Login to comment...