16.12 Companion Objects
A Kotlin class can also contain a companion object. A companion object contains methods and variables that are common to all instances of the class. In addition to being accessible via class instances, these properties are also accessible at the class level (in other words without the need to create an instance of the class).
The syntax for declaring a companion object within a class is as follows:
class ClassName: ParentClass {
// Properties
// Methods
companion object {
// properties
// methods
}
}
To experience a companion object example in action, enter the following into the Kotlin online playground at https://try.kotl.in:
class MyClass {
fun showCount() {
...