Bird
0
0

Which of the following is the correct syntax to declare an instance field named score of type int inside a class?

easy📝 Syntax Q3 of 15
C Sharp (C#) - Classes and Objects
Which of the following is the correct syntax to declare an instance field named score of type int inside a class?
Aint score() {}
Bpublic int score;
Cstatic int score;
Dint score = method();
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct field declaration

    Instance fields are declared as variables inside the class, e.g., 'public int score;'.
  2. Step 2: Eliminate incorrect options

    int score() {} is a method, C is static (not instance), D assigns from a method call which is invalid here.
  3. Final Answer:

    public int score; -> Option B
  4. Quick Check:

    Instance field syntax = variable declaration [OK]
Quick Trick: Declare instance fields as variables inside the class [OK]
Common Mistakes:
MISTAKES
  • Using parentheses like a method
  • Declaring fields as static by mistake
  • Assigning values from methods in declaration incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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