Bird
0
0

You want to track how many times each Player object has scored points. Which design correctly uses instance fields to store this state?

hard🚀 Application Q8 of 15
C Sharp (C#) - Classes and Objects
You want to track how many times each Player object has scored points. Which design correctly uses instance fields to store this state?
class Player {
  public int scoreCount = 0;
  public void Score() {
    scoreCount++;
  }
}

What happens when you create two players and call Score() on each once?
ACompilation error due to missing static keyword
BEach player has its own scoreCount incremented to 1
CscoreCount resets to 0 after each call
DBoth players share one scoreCount incremented to 2
Step-by-Step Solution
Solution:
  1. Step 1: Understand instance field behavior

    scoreCount is an instance field, so each Player object has its own copy.
  2. Step 2: Analyze method effect on objects

    Calling Score() on each player increments their own scoreCount separately.
  3. Final Answer:

    Each player has its own scoreCount incremented to 1 -> Option B
  4. Quick Check:

    Instance fields track per-object state [OK]
Quick Trick: Instance fields keep separate data for each object [OK]
Common Mistakes:
MISTAKES
  • Confusing instance fields with static fields
  • Expecting shared state across objects
  • Assuming scoreCount resets automatically

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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