0

Kotlin – create static fields and methods

This post demonstrates how to create static class members similar to that of Java. We use Kotlin 1.1 here.

All static members Class

If we want to create a class that only contains static members, we use singletons in Kotlin. For example:

Outputs:

Static and non-static members in class

Sometimes we have classes that have both static and non-static class members in Java. In Kotlin, we can mix static and non-static members in one class. For example:

Outputs:

References

https://kotlinlang.org/docs/reference/classes.html