Bird
Raised Fist0

Which of the following is the correct syntax to create a new object of class Person?

easy📝 Syntax Q12 of Q15
C Sharp (C#) - Classes and Objects
Which of the following is the correct syntax to create a new object of class Person?
APerson p = new Person;
BPerson p = Person.new();
CPerson p = new Person();
DPerson p = Person();
Step-by-Step Solution
Solution:
  1. Step 1: Check correct use of new keyword and parentheses

    In C#, to create a new object, you must use new ClassName() with parentheses.
  2. Step 2: Analyze each option

    Person p = new Person(); uses new Person(); correctly. Person p = Person.new(); uses wrong syntax with dot notation. Person p = new Person; misses parentheses. Person p = Person(); misses new.
  3. Final Answer:

    Person p = new Person(); -> Option C
  4. Quick Check:

    Correct syntax = A [OK]
Quick Trick: Always use new ClassName() with parentheses [OK]
Common Mistakes:
MISTAKES
  • Omitting parentheses after class name
  • Using dot notation with new
  • Forgetting the new keyword

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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