Bird
0
0

Which of the following is the correct way to declare a private field in a C# class?

easy📝 Syntax Q12 of 15
C Sharp (C#) - Properties and Encapsulation
Which of the following is the correct way to declare a private field in a C# class?
Aprivate int age;
Bpublic int age;
Cint private age;
Dprivate: int age;
Step-by-Step Solution
Solution:
  1. Step 1: Recall C# syntax for access modifiers

    In C#, the keyword private comes before the type and variable name.
  2. Step 2: Check each option

    private int age; uses private int age; which is correct syntax for a private field.
  3. Final Answer:

    private int age; -> Option A
  4. Quick Check:

    Private field syntax = private int age; [OK]
Quick Trick: Private fields start with 'private' keyword before type [OK]
Common Mistakes:
MISTAKES
  • Using 'public' instead of 'private' for private fields
  • Placing 'private' after the type
  • Using C++ style 'private:' which is invalid in C#

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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