1Z0-811 · Question #33
Which statement is valid?
The correct answer is A. int 2 totalScore = 0. There appears to be an error in the provided answer key - A is not correct. int 2 totalScore = 0; is invalid because variable names cannot begin with a digit, and it contains a space, making it unparseable. The actual correct answers are B and C (both are valid declarations)…
Question
Options
- Aint 2 totalScore = 0;
- Bint totalScore = 0;
- Cint totalScore2 = 0;
- Dint total score = 0;
How the community answered
(45 responses)- A91% (41)
- B4% (2)
- C2% (1)
- D2% (1)
Explanation
There appears to be an error in the provided answer key - A is not correct. int 2 totalScore = 0; is invalid because variable names cannot begin with a digit, and it contains a space, making it unparseable. The actual correct answers are B and C (both are valid declarations). Here's the proper breakdown:
B (int totalScore = 0;) and C (int totalScore2 = 0;) are both valid - identifiers can contain digits, they just cannot start with one.
A (int 2 totalScore = 0;) is invalid for two reasons: it starts with a digit (2) and contains a space, neither of which is allowed in an identifier.
D (int total score = 0;) is invalid because the space makes total score two separate tokens - the compiler sees total as the variable name and score as an unexpected symbol.
Memory tip: Think of variable names like usernames - they can have letters and numbers, but must start with a letter (or _/$), and spaces are never allowed.
Note for the exam: If this is a single-answer question and you must choose one, B is the safer pick as it's the most canonical example. But you should flag this with your instructor, as C is equally valid.
Topics
Community Discussion
No community discussion yet for this question.