Bird
Raised Fist0

Identify the error in this class declaration:

medium📝 Debug Q6 of Q15
C Sharp (C#) - Classes and Objects
Identify the error in this class declaration:
public class Car
{
  public string Model;
  private int year
}
AClass name should be lowercase
BAccess modifier 'private' is invalid
CMissing semicolon after 'year' field
DFields cannot be declared inside classes
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax of field declarations

    Each field declaration must end with a semicolon.
  2. Step 2: Locate missing semicolon

    The field private int year is missing a semicolon at the end.
  3. Final Answer:

    Missing semicolon after 'year' field -> Option C
  4. Quick Check:

    Field declarations require semicolons [OK]
Quick Trick: Always end field declarations with semicolon [OK]
Common Mistakes:
MISTAKES
  • Omitting semicolon
  • Thinking class names must be lowercase
  • Believing private is invalid

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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