Bird
0
0

Find the error in this constructor overloading example:

medium📝 Debug Q7 of 15
C Sharp (C#) - Classes and Objects
Find the error in this constructor overloading example:
class Book {
  public Book(string title) {}
  public Book(string title, string author) {}
  public Book(string author) {}
}
AConstructor names do not match class name
BMissing return type in constructors
CConstructors must have different names
DTwo constructors have the same parameter type and count
Step-by-Step Solution
Solution:
  1. Step 1: Check parameter lists

    Two constructors have one string parameter each: Book(string title) and Book(string author).
  2. Step 2: Understand overloading rules

    Overloading requires different parameter types or counts; these two have identical signatures causing error.
  3. Final Answer:

    Two constructors have the same parameter type and count -> Option D
  4. Quick Check:

    Parameter signature must differ for overloading [OK]
Quick Trick: Parameter types and counts must differ to overload [OK]
Common Mistakes:
MISTAKES
  • Assuming parameter names affect overloading
  • Thinking constructors can have different names
  • Adding return types to constructors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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