C#.NET — Object size with only interface implementations: what is the instance size? A class implements two interfaces (each with three methods) and has no instance fields. What is the size of an object created from this class?

Difficulty: Easy

Correct Answer: 0 byte

Explanation:

Introduction / Context:In managed languages such as C#, object layout is abstracted away by the runtime. Exams often check whether you incorrectly assume that “more methods or interfaces mean a larger object.”

Given Data / Assumptions:

  • The class implements interfaces only; it has no instance fields.
  • We are asked about the size of an instance.

Concept / Approach:In exam-oriented C# questions, instance size is typically considered as coming from instance fields. Methods (including interface implementations) are shared code and do not add per-object data. Therefore, with no fields, the instance is treated as having “0 byte” payload in such questions—even though actual CLR objects have a header and alignment that are not part of this simplified model.

Step-by-Step Solution:

Interfaces add no per-instance data in this simplified view. No instance fields → no per-instance storage → reported as 0 byte in typical MCQ keys. Remember that the real CLR adds object headers; that detail is intentionally ignored in these exam questions.

Verification / Alternative check:Using reflection or unsafe code reveals real headers; however, MCQs usually abstract that away to emphasize that methods/interfaces don’t increase instance size.

Why Other Options Are Wrong:They assume a fixed byte size unrelated to instance fields or mix in header sizes, which the exam does not request.

Common Pitfalls:Confusing code size with object instance size; believing more methods or interfaces make each object larger.

Final Answer:0 byte

More Questions from Interfaces

Discussion & Comments

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