C# Programming - Classes and Objects - Discussion

Discussion Forum : Classes and Objects - General Questions (Q.No. 14)
14.
Which of the following statements are correct about objects of a user-defined class called Sample?
  1. All objects of Sample class will always have exactly same data.
  2. Objects of Sample class may have same or different data.
  3. Whether objects of Sample class will have same or different data depends upon a Project Setting made in Visual Studio.NET.
  4. Conceptually, each object of Sample class will have instance data and instance member functions of the Sample class.
  5. All objects of Sample class will share one copy of member functions.
1, 3
2, 4
4, 5
3, 5
None of these
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
5 comments Page 1 of 1.

Nicholas Mahbouby said:   1 decade ago
2). The term "different data" is ambiguous in this context. Objects of the same class have their own separate instance data but one object could be an identical copy of the other, thus having the same but separate data.

4). The word "conceptually" is key here. Instance fields and methods are implicitly accessed through the this reference even when the this keyword is not specified. For the purpose of C# programming, every object does conceptually have it's own instance members.

5). The CLR is free to optimize memory allocation any way it sees fit. The statement "new int[1000000000]" allocates 1 billion System.Int32 objects. I'm sure there are not 1 billion copies of the code for every method of every instance. You would soon run out of memory.

Rolandas said:   1 decade ago
Missing detailed class definition. 4 & 5 are incompatible: 4 is dedicated for instance classes, 5 for static classes.

Wageesha said:   1 decade ago
Answer should be 2 & 4.

"All objects of Sample class will share one copy of member functions" is extremely wrong. For each object, separate set of methods will be created in the memory.

VigneshG said:   1 decade ago
Statement 2 should also be true. Objects "may" have same or different data. And if option 4 is correct then B. 2, 4 should also be correct.

Sandeep said:   1 decade ago
All objects of Sample class will share one copy of member functions. Seems Wrong.

Post your comments here:

Your comments will be displayed after verification.