Bird
Raised Fist0

Which constructor declaration correctly chains to another constructor within the same class in C#?

easy📝 Syntax Q3 of Q15
C Sharp (C#) - Inheritance
Which constructor declaration correctly chains to another constructor within the same class in C#?
Apublic MyClass() : this(100) { }
Bpublic MyClass() { this(100); }
Cpublic MyClass() => this(100);
Dpublic MyClass() call this(100);
Step-by-Step Solution
Solution:
  1. Step 1: Recall constructor chaining syntax

    In C#, chaining is done using the colon ':' followed by 'this' and the argument list.
  2. Step 2: Analyze options

    public MyClass() : this(100) { } uses correct syntax: : this(100). Options B, C, and D use invalid syntax.
  3. Final Answer:

    public MyClass() : this(100) { } -> Option A
  4. Quick Check:

    Constructor chaining uses ': this(args)' syntax [OK]
Quick Trick: Use ': this(args)' to chain constructors [OK]
Common Mistakes:
MISTAKES
  • Calling constructor inside body instead of initializer
  • Using arrow syntax incorrectly for chaining
  • Using invalid keywords like 'call'

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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