Bird
0
0

Which of the following is true about a constructor in C#?

easy🧠 Conceptual Q2 of 15
C Sharp (C#) - Classes and Objects
Which of the following is true about a constructor in C#?
AA constructor must have the same name as the class and no return type.
BA constructor can have any name but must return void.
CA constructor must have a return type and can have any name.
DA constructor is a method that must return an integer.
Step-by-Step Solution
Solution:
  1. Step 1: Recall constructor naming rules

    Constructors must have the exact same name as the class and no return type.
  2. Step 2: Eliminate incorrect options

    Constructors cannot have return types or arbitrary names.
  3. Final Answer:

    A constructor must have the same name as the class and no return type. -> Option A
  4. Quick Check:

    Constructor naming = B [OK]
Quick Trick: Constructor name = class name, no return type. [OK]
Common Mistakes:
MISTAKES
  • Adding a return type to constructors
  • Using different names for constructors
  • Confusing constructors with regular methods

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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