Bird
0
0

What is the output of this code?

medium📝 Predict Output Q13 of 15
C Sharp (C#) - Properties and Encapsulation
What is the output of this code?
class Box {
  public int Width { get; set; } = 3;
  public int Height { get; set; } = 4;
  public int Area => Width * Height;
}

var box = new Box();
Console.WriteLine(box.Area);
A12
B7
C0
DError
Step-by-Step Solution
Solution:
  1. Step 1: Identify property values

    Width is 3 and Height is 4 as set by default.
  2. Step 2: Calculate computed property Area

    Area returns Width * Height = 3 * 4 = 12.
  3. Final Answer:

    12 -> Option A
  4. Quick Check:

    3 * 4 = 12 [OK]
Quick Trick: Multiply Width and Height for Area [OK]
Common Mistakes:
MISTAKES
  • Adding instead of multiplying
  • Assuming default values are zero
  • Confusing property with method call

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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