Skip to content

Commit 0eec4bf

Browse files
authored
Merge pull request #366 from DieuMerci225/chapter9.4
Chapter9.4
2 parents 2565333 + 39eac50 commit 0eec4bf

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

source/ch9_commonmistakes.ptx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,9 @@
121121
<section xml:id="not-importing-a-class">
122122
<title>Not importing a class</title>
123123
<p>
124-
In Python, many classes are available by default. However, in Java, you must explicitly import most classes from external packages that you want to use.
124+
In Python, many classes are available by default. However, in Java, you must explicitly import most classes from external packages that you want to use <xref ref="importing-classes" text="type-global"/>. If you forget to import a class, the compiler will give you an error message like this:
125125
</p>
126+
<listing xml:id="importing-classes">
126127
<program language="java" interactive="activecode" line-numbers="yes">
127128

128129
<code>
@@ -137,8 +138,9 @@
137138
} // End of class
138139
</code>
139140
</program>
141+
</listing>
140142
<p>
141-
You may notice that this error message looks similar to the previous one, however, it has an entirely different cause. In Java, classes like <c>Scanner</c> that are part of external packages (like <c>java.util</c>) must be explicitly imported into your source file. Java does not automatically recognize these classes. To resolve this error, you need to add an import statement for the <c>Scanner</c> class at the beginning of your <c>Histo.java</c> file, typically import <c>java.util.Scanner;</c>.
143+
You may notice that this error message looks similar to the previous one <xref ref="undeclared-variable" text="type-global"/>, however, it has an entirely different cause. In Java, classes like <c>Scanner</c> that are part of external packages (like <c>java.util</c>) must be explicitly imported into your source file. Java does not automatically recognize these classes. To resolve this error, you need to add an import statement for the <c>Scanner</c> class at the beginning of your <c>Histo.java</c> file, typically import <c>java.util.Scanner;</c>.
142144
</p>
143145

144146
</section>

0 commit comments

Comments
 (0)