Core facts about classes and objects in C#: select the correct statements. 1) Instance members of a class can be accessed only through an object of that class. 2) A class can contain only instance data and instance member functions. 3) All objects created from a class occupy an equal number of bytes in memory. 4) A class can contain Friend (internal) functions. 5) A class is a blueprint/template from which objects are created.

Difficulty: Easy

Correct Answer: 1, 3, 5

Explanation:


Introduction / Context:
This item checks basic OO knowledge in C#. It tests how instance members are accessed, what a class can contain, object layout, access modifiers, and the conceptual role of a class.



Given Data / Assumptions:

  • Standard C# semantics for instance vs. static members.
  • Typical class instances have fixed layout determined by the class definition.
  • “Friend” corresponds to VB’s keyword (internal in C#), but the option's phrasing is ambiguous.


Concept / Approach:
(1) True: Outside the class, you access instance members via an instance reference; inside, you use this (still an object). (2) False: classes can also have static members. (3) True: instances of the same class share the same layout, so each object of that class occupies the same number of bytes (ignoring runtime headers and GC internals which are uniform). (4) As written, “Friend functions” is a VB term; in C#, the equivalent is internal. The statement is not accurate in C# context. (5) True: class as blueprint/template is a standard definition.



Step-by-Step Solution:

Select 1, 3, and 5.Exclude 2 and 4 based on the reasons above.


Verification / Alternative check:
Review the C# language specification for member access and type members; instance size comes from the class’s field composition.



Why Other Options Are Wrong:
They include statement 2 or 4 which are not correct as stated.



Common Pitfalls:
Confusing C# keywords with VB’s; forgetting that static members exist and are not tied to instances.



Final Answer:
1, 3, 5

Discussion & Comments

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