Packages and imports
A source file may start with a package declaration:
All the contents, such as classes and functions, of the source file are included in this package. So, in the example above, the full name of
org.example.printMessage, and the full name of
If the package is not specified, the contents of such a file belong to the default package with no name.
A number of packages are imported into every Kotlin file by default:
Additional packages are imported depending on the target platform:
Apart from the default imports, each file may contain its own
You can import either a single name:
or all the accessible contents of a scope: package, class, object, and so on:
If there is a name clash, you can disambiguate by using
as keyword to locally rename the clashing entity:
import keyword is not restricted to importing classes; you can also use it to import other declarations:
Visibility of top-level declarations
If a top-level declaration is marked
private, it is private to the file it's declared in (see Visibility modifiers).