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:
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:
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