C#.NET — Objects, instance data, and shared behavior: choose the correct statements about a user-defined class Sample. Statements: All objects of Sample will always have exactly the same data. Objects of Sample may have the same or different data. Whether objects of Sample have the same or different data depends on a Visual Studio project setting. Conceptually, each object of Sample has its own instance data and exposes the instance member functions (behavior) of Sample. All objects of Sample share one copy of member functions.

Difficulty: Easy

Correct Answer: 2, 4

Explanation:


Introduction / Context:
This question targets the fundamentals of object instances in C#. Objects have state (fields) and behavior (methods). States vary per instance; behavior is defined once in the type and is callable on each instance.



Given Data / Assumptions:

  • Sample is a class (reference type).
  • We distinguish per-object state from class-defined behavior.


Concept / Approach:
Each object holds its own copy of instance fields, so two objects can hold different values. Methods are defined on the type and are invoked with a this reference; conceptually each object “has” those behaviors, though the implementation is a single method body shared by all instances.



Step-by-Step Solution:

(1) False — objects can have different field values.(2) True — they may be same or different depending on assignments.(3) False — not controlled by IDE settings.(4) True — conceptually, every object exposes instance behavior and owns its own data.(5) Implementation detail: yes, method code is shared, but the better paired truth here is (2) and (4) as per conceptual MCQ framing.


Verification / Alternative check:
Create two Sample objects, set different field values; methods act on each object’s this.



Why Other Options Are Wrong:
(1) and (3) are plainly incorrect; (5) alone without (2) omits the crucial property of per-object data.



Common Pitfalls:
Confusing the single method implementation with per-object behavior; the important takeaway is that objects don’t share instance data.



Final Answer:
2, 4

More Questions from Classes and Objects

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion