Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q4 of 15
C Sharp (C#) - Properties and Encapsulation
What will be the output of this code?
class Car {
  public string Model { get; set; }
}

var car = new Car();
car.Model = "Tesla";
Console.WriteLine(car.Model);
ACompilation error
BModel
CTesla
Dnull
Step-by-Step Solution
Solution:
  1. Step 1: Understand property assignment

    The property Model is set to "Tesla" using the set accessor.
  2. Step 2: Output the property value

    Console.WriteLine prints the value of Model, which is "Tesla".
  3. Final Answer:

    Tesla -> Option C
  4. Quick Check:

    Property value set and printed = Tesla [OK]
Quick Trick: Set property value before reading it [OK]
Common Mistakes:
MISTAKES
  • Expecting property name printed instead of value
  • Assuming default null is printed
  • Thinking code causes error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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