Skip to content
Learn Netverks

Lesson

Step 15/36 42% through track

interfaces-kotlin

Interfaces

Last reviewed Jun 1, 2026 Content v20260601
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches Interfaces: the syntax, patterns, and safety habits you need before advancing in Kotlin.

Teams still ship Interfaces in Kotlin codebases—skipping it leaves gaps in debugging and code reviews.

You will apply Interfaces in contexts like: Android apps, Spring services, and shared KMP modules.

Write Kotlin in main.kt with fun main(), click Run on server—the dev runner kotlinc compiles to a JVM jar and java runs it; use println for output (requires JDK + kotlinc; LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

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

  1. 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.
  2. Q: Can interfaces have code?
    A: Yes—default method bodies in interfaces are common for small shared helpers.

Self-check

  1. How many interfaces can one class implement?
  2. 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.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • Default impl?
  • Functional interface?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump