🐦 Kotlin Beginner

What is an object declaration in Kotlin?

Answer

The object keyword creates a singleton — a class with exactly one instance that is created lazily on first access in a thread-safe manner. You declare it like a class but without a constructor: object DatabaseManager { fun connect() {} }. Access it directly by name: DatabaseManager.connect(). This replaces the verbose singleton pattern from Java. Object declarations can extend classes and implement interfaces. They are perfect for utility classes, managers, and anything that should have only one instance in the application.