C++ | Class and Object | Question 4

Which of the following is true?
(A) All objects of a class share all data members of class
(B) Objects of a class do not share non-static members. Every object has its own copy.
(C) Objects of a class do not share codes of non-static methods, they have their own copy
(D) 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

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.