Kotlin interfaces can declare abstract members and provide default implementations—similar to Java 8+ interfaces and C# default interface methods. A class may implement multiple interfaces.
Implementing interfaces
interface Greeter {
fun greet(name: String): String
}
class LoudGreeter : Greeter {
override fun greet(name: String) = "HELLO, $name"
}
Interface properties can be abstract or have getters; no backing field unless you are in a class implementation.
Compared to Java
After Java interfaces, Kotlin feels familiar—no separate implements keyword; use a colon and comma-separated supertypes: class Foo : Bar, Baz.
Important interview questions and answers
- Q: Interface vs abstract class?
A: Interfaces support multiple inheritance of behavior contracts; abstract classes carry state and single inheritance—pick interfaces for capabilities, abstract classes for shared base state. - Q: Can interfaces have code?
A: Yes—default method bodies in interfaces are common for small shared helpers.
Self-check
- How many interfaces can one class implement?
- What keyword marks interface implementation?
Tip: Keep interfaces small—default implementations help evolve APIs without breaking implementers.
Interview prep
- Multiple interfaces?
class Foo : A, B supported.
- Default implementations?
Interfaces can include method bodies.