Notes on import Declarations
Notice the import
declaration in Fig. B.4 (line 4). This indicates to the compiler that the program uses class Scanner
. Why do we need to import class Scanner
, but not classes System
, String
or GradeBook
? Classes System
and String
are in package java.lang
, which is implicitly imported into every Java program, so all programs can use that package’s classes without explicitly importing them. Most other classes you’ll use in Java programs must be imported explicitly.
There’s a special relationship between classes that are compiled in the same directory on disk, like classes GradeBook
and GradeBookTest
. By default, such classes are considered to be in the same package—known as the default package. Classes in the same ...
Get Android™ How to Program, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.