Packages

A package is a logical grouping of related classes, interfaces, enumerations, annotations, and functions. As source files grow larger, it is necessary to group these files into meaningful and distinct collections for various reasons, such as to enhance the maintainability of applications, name conflict prevention, and access control.

A package is created with the package keyword followed by a package name:

package foo

There can be only one package statement per program file. If a package for a program file is not specified, the contents of the file are placed into the default package.

Get Kotlin Programming By Example 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.