Bird
0
0

Identify the error in this constructor overloading code:

medium📝 Debug Q14 of 15
C Sharp (C#) - Classes and Objects
Identify the error in this constructor overloading code:
class Person {
  public string name;
  public Person(string n) { name = n; }
  public Person(string n) { name = n.ToUpper(); }
}
AConstructor name does not match class name
BMissing return type in constructors
CDuplicate constructor with same parameter list
DCannot assign string to name
Step-by-Step Solution
Solution:
  1. Step 1: Check constructor parameter lists

    Both constructors have the same parameter type and count (string n), causing duplication.
  2. Step 2: Understand overloading rules

    Constructors must differ by parameter types or count to overload; identical signatures cause error.
  3. Final Answer:

    Duplicate constructor with same parameter list -> Option C
  4. Quick Check:

    Same parameters = duplicate constructor error [OK]
Quick Trick: Constructor signatures must differ by parameters [OK]
Common Mistakes:
MISTAKES
  • Thinking constructors can differ by body only
  • Adding return type mistakenly
  • Ignoring parameter list uniqueness

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Sharp (C#) Quizzes