> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Kotlin Interface

An interface in Kotlin is a custom type that defines a contract of abstract methods and properties for implementing classes. Unlike abstract classes, interfaces cannot maintain state—they cannot instantiate backing fields—but they can provide default implementations for their functions and property accessors. Kotlin supports multiple interface inheritance, allowing a single class or object to implement multiple interfaces.

## Declaration and Implementation

Interfaces are declared using the `interface` keyword. By default, all members are `public` and `open`. A class or object implements an interface using the `:` operator and must provide implementations for all abstract members using the `override` modifier.

```kotlin theme={"dark"}
interface Clickable {
    fun click() // Abstract method, requires implementation
    
    fun hover() { // Concrete method with default implementation
        println("Hovering")
    }
}

class Button : Clickable {
    override fun click() {
        println("Button clicked")
    }
    // hover() is inherited automatically, but can be overridden
}
```

## Interface Properties

Properties declared in an interface can either be abstract or provide implementations for their accessors (`get` / `set`). Because interfaces cannot hold state, properties cannot be initialized directly, nor can they utilize a `field` identifier (backing field).

```kotlin theme={"dark"}
interface User {
    val id: String // Abstract property, must be overridden in implementing class
    
    val role: String
        get() = "Guest" // Property with custom getter, no backing field
        
    // var count: Int = 0 // ERROR: Property initializers are not allowed in interfaces
}

class StandardUser(override val id: String) : User
```

## Resolving Overriding Conflicts

When a class implements multiple interfaces that contain methods with identical signatures and default implementations, the compiler mandates that the implementing class explicitly override the conflicting method. The `super<InterfaceName>` syntax is used to invoke specific interface implementations.

```kotlin theme={"dark"}
interface A {
    fun execute() { println("A") }
}

interface B {
    fun execute() { println("B") }
}

class C : A, B {
    override fun execute() {
        super<A>.execute() // Invokes A's implementation
        super<B>.execute() // Invokes B's implementation
    }
}
```

## Interface Inheritance

Interfaces can inherit from one or multiple other interfaces. A derived interface can declare new members, provide default implementations for inherited abstract members, or override inherited properties. Classes implementing the derived interface are only required to implement the remaining abstract members.

```kotlin theme={"dark"}
interface Named {
    val name: String
}

interface Person : Named {
    val firstName: String
    val lastName: String
    
    // Overriding the inherited abstract property with a custom getter
    override val name: String 
        get() = "$firstName $lastName"
}

class Employee(
    override val firstName: String,
    override val lastName: String
) : Person // 'name' is already implemented by the Person interface
```

## Functional (SAM) Interfaces

An interface with exactly one abstract method is known as a Functional Interface or a Single Abstract Method (SAM) interface. By declaring it with the `fun` modifier, Kotlin enables SAM conversion, allowing you to instantiate the interface using lambda expressions.

```kotlin theme={"dark"}
fun interface IntPredicate {
    fun accept(i: Int): Boolean
}

// Instantiation via SAM conversion (lambda)
val isEven = IntPredicate { it % 2 == 0 }
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Kotlin Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
