Intermediate 7 min readKotlin 2.0

Kotlin Interfaces — Contracts with Default Implementations

An interface defines a contract that classes can implement. Kotlin interfaces can have abstract functions and default implementations.

What You Will Learn

  • Declare interfaces
  • Implement an interface
  • Use default method bodies
  • Implement multiple interfaces
  • Interface properties

Declaring and Implementing

Interfaces use the interface keyword. Classes implement with : InterfaceName.

Basic Interface

kotlin
interface Printable {
    fun print()
    fun printTwice() {
        print()
        print()
    }
}

class Document(val content: String) : Printable {
    override fun print() {
        println(content)
    }
}

fun main() {
    val doc = Document("Hello, Interface!")
    doc.print()
    doc.printTwice()
}
Output
Hello, Interface! Hello, Interface! Hello, Interface!

print() is abstract — Document must implement it. printTwice() has a default implementation that calls print(). Document gets printTwice() for free.

Best Practice: Prefer interfaces over abstract classes for defining contracts. Kotlin classes can implement multiple interfaces but can only extend one class.

Multiple Interfaces

A class can implement many interfaces.

Multiple Interfaces

kotlin
interface Flyable {
    fun fly() = println("Flying")
}

interface Swimmable {
    fun swim() = println("Swimming")
}

class Duck : Flyable, Swimmable

fun main() {
    val duck = Duck()
    duck.fly()
    duck.swim()
}
Output
Flying Swimming

Duck implements both interfaces and inherits both default implementations. No override needed since no conflict exists.

Practice Exercise

Exercisemultiple choice

Can a Kotlin interface have a default method implementation?

Quick Quiz

Quick Quiz

How many interfaces can a Kotlin class implement?

Frequently Asked Questions

Related Tutorials

Last updated: 2026-05-01Kotlin 2.0

Written by KotlinGuide Editorial Team · Reviewed by KotlinGuide Technical Review