Problem Statement
What is a companion object in Kotlin?
Explanation
Companion objects are declared inside a class with the companion object keywords, and their members can be accessed using the class name like ClassName dot memberName similar to Java static members. A class can have only one companion object, which can implement interfaces, extend classes, and have its own properties and functions.
Companion objects are useful for factory methods, constants related to the class, or methods that don't need instance state. Unlike Java static members, companion objects are actual objects that can inherit from classes and implement interfaces, making them more flexible for polymorphism and dependency injection.