Bird
0
0

What will be the output of this C# code?

medium📝 Predict Output Q4 of 15
C Sharp (C#) - Classes and Objects
What will be the output of this C# code?
class Book {
  public string Title = "C# Basics";
}

Book b = new Book();
Console.WriteLine(b.Title);
Ab.Title
BTitle
CC# Basics
DError: Title not found
Step-by-Step Solution
Solution:
  1. Step 1: Understand object creation and field access

    The code creates an object 'b' of class Book and accesses its 'Title' field.
  2. Step 2: Determine the output of Console.WriteLine(b.Title)

    The 'Title' field contains "C# Basics", so that string is printed.
  3. Final Answer:

    C# Basics -> Option C
  4. Quick Check:

    Object field access = Printed value [OK]
Quick Trick: Access object fields with dot notation [OK]
Common Mistakes:
MISTAKES
  • Expecting variable name printed
  • Confusing field name with value
  • Thinking code causes error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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