diff --git a/source/ch9_commonmistakes.ptx b/source/ch9_commonmistakes.ptx index 64b59cd..4dca391 100644 --- a/source/ch9_commonmistakes.ptx +++ b/source/ch9_commonmistakes.ptx @@ -115,6 +115,56 @@

The 'cannot find symbol' error for the variable count on line 6 indicates that count was used before it was declared within the Histo class. In Java, all variables must be explicitly declared with a data type (e.g., int, String, ArrayList<Integer>) before they can be assigned a value or referenced in any way. The arrow in the error message points to where the undeclared variable count was first encountered. To resolve this, count needs to be declared with its appropriate type (e.g., ArrayList<Integer> count;) before any attempt to initialize or use it.

+ + +

+ Based on , select all of the + statements that are true about declaring variables in Java. +

+
+ + + +

Every variable must be declared with a data type before it is used.

+
+ +

Correct! Java requires a variable to be declared with its type before it can be assigned or referenced.

+
+
+ + +

The "cannot find symbol" error happens because count was used before being declared.

+
+ +

Correct! That error means the compiler reached a variable it has no declaration for.

+
+
+ + +

Writing ArrayList<Integer> count; before using count would fix the "cannot find symbol" error.

+
+ +

Correct! Declaring count with its type resolves the error.

+
+
+ + +

Java lets you use a variable without declaring it first, just like Python.

+
+ +

Incorrect. Unlike Python, Java requires all variables to be declared before use.

+
+
+ + +

The error can be fixed by adding an import statement.

+
+ +

Incorrect. The import is already present; the problem is the missing variable declaration, not a missing import.

+
+
+
+