Operator overloading and member hiding in C#.NET — choose all correct statements (single best answer option lists all true ones).

Difficulty: Medium

Correct Answer: Operator overloading permits using symbolic operators to express computations for a user-defined type; at least one operand must be the containing type.

Explanation:


Introduction / Context:
This item checks understanding of method overloading, operator overloading constraints, and the use of the new modifier for hiding.



Given Data / Assumptions:

  • User-defined types may overload selected operators.
  • new can hide members (including nested types).
  • Overloading (methods) vs operator overloading (operators) have different rules.


Concept / Approach:
In C#, not all operators are overloadable (for example, new, sizeof, =, && cannot be overloaded). Operator overloads must be static and at least one operand must be the declaring type. Method overloading allows multiple methods with the same name but different signatures.



Step-by-Step Solution:

1) Option A: false — not all operators are overloadable; operands cannot both be unrelated types.2) Option B: true statement, but does not alone capture all requirements of the question.3) Option C: true for method overloading.4) Option D: true and the most complete/precise operator-overloading rule (best single answer).5) Option E: false — at least one operand must be the containing type (often exactly that).


Verification / Alternative check:
Implement a simple struct with operator + and confirm that the overload must be static and include the struct as an operand.



Why Other Options Are Wrong:
A and E violate language rules; B and C are correct statements but D is the most complete and directly addresses operator overloading constraints.



Common Pitfalls:
Equating new (hiding) with override (polymorphism), and assuming all operators can be overloaded.



Final Answer:
Operator overloading permits using symbolic operators to express computations for a user-defined type; at least one operand must be the containing type.

Discussion & Comments

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