Java var ArrayList Reassignment Compilation in 1Z0-819
Given: Which is true? - 
Community Votes
67% of anonymous learners picked answer D. Votes are pick records left by other test-takers — they are not the verified answer.
Community Insight
The question tests
vartype inference with parameterized types; the common trap is misreading the lowercaselinlistAas an uppercaseL, or wrongly assuming generic invariance blocks the assignment.
This 1Z0-819 question tests local variable type inference with generic collections: var listA = new ArrayList<String>() and var listC = new ArrayList<String>() compile fine, and the reassignment listA = listC on line 13 is valid. The program compiles without errors (D).
The most common wrong answer is B (fails on line 13), chosen because learners misread `listA` as `ListA` or mistakenly believe that two `ArrayList<String>` variables cannot be assigned to each other.
Community Discussion (5 comments)
Comments & Corrections
No comments yet — spotted an error or have a note? Share it below.
Expert Analysis
Why the Answer Is Correct
The code usesvar to declare listA, listB, and listC as ArrayList<String> (or compatible types). Line 10 declares listA with no error, line 11 declares listB with no error, and line 13's assignment listA = listC; is valid because both variables have the same inferred parameterized type. var in Java 10+ infers the exact static type from the initializer, including generics, so listA and listC are both ArrayList<String>. The program therefore compiles fine, making D the correct answer.Why the Other Options Are Wrong
Option A (fails on line 10) is wrong becausevar listA = new ArrayList<String>; is a perfectly legal declaration; var can be used with parameterized constructors. Option C (fails on line 11) is wrong for the same reason; var listB = new ArrayList<Integer>; also compiles. Option B (fails on line 13) would only be correct if line 13 used an undeclared identifier like ListA (capital L) or if listA and listC had incompatible generic types, but neither is the case in the intended code. The assignment of a List<String> to an ArrayList<String> would fail, but here both are ArrayList<String>.Community Comment Notes
Many learners, such as d7bb0b2, correctly noted that "if syntax is good (listA not ListA...) program compile fine." ASPushkin similarly commented that "even listA = listC; is good." Some learners like bf8f3be read line 13 as "ListA" and voted B, but this appears to be a misreading of the image's font; the intended code uses lowercaselistA. The consensus among those who read the variable name correctly is that the program compiles without error. Official Reference
Exam Strategy
When a question shows var with generic collections, verify the inferred type of each variable from its initializer. Don't let a blurry image or a case-sensitivity typo distract you from the actual type compatibility rules.
Frequently Asked Questions
Why does line 13 compile when using var with ArrayList?
Because var infers the full generic type ArrayList<String> for both listA and listC, making the assignment valid.
What if line 13 used ListA instead of listA?
Then it would be a compile error because ListA is an undeclared identifier, but that is a typo not present in the intended exam code.