Interfaces & Abstract Classes

An interface is a contract of capabilities a type can declare and optionally implement, while an abstract class is a partially-implemented base that can also hold state and a constructor.

Learn Interfaces & Abstract Classes in our free Kotlin course — a beginner-friendly interactive lesson with worked examples, a practice exercise and a quick…

Part of the free Kotlin course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.

You'll learn abstract and default methods, properties in interfaces, implementing multiple interfaces, when to choose an abstract class, and resolving conflicts with super<Type> .

What You'll Learn in This Lesson

1️⃣ Interfaces: Abstract + Default Members

An interface declares what a type can do. A method with no body is abstract — every implementer must provide it. A method with a body is a default implementation that implementers inherit for free. Interfaces can also declare properties , though those must be abstract or computed (no stored value).

The override keyword is required when implementing an interface member, and the default greetLoudly() reuses the abstract greet() without the class writing it again.

2️⃣ Implementing Multiple Interfaces

A class can implement several interfaces at once — that's how Kotlin composes independent behaviours despite allowing only one superclass. If two interfaces provide a default method with the same signature, the compiler forces you to override it and pick which implementation to use via super<Interface> .

Inside the override you can call one, the other, or both qualified supers — here Duck.move() combines them.

3️⃣ Abstract Classes: State + Constructor

An abstract class goes further than an interface: it can store real properties, run a constructor, and keep internal state, while still leaving some members abstract for subclasses to implement. Use one when subclasses share state or setup logic; use an interface when you only need to declare capabilities or mix several together.

Shape holds a name and provides a concrete describe() , while each subclass supplies its own area() — something a pure interface couldn't do with stored state.

Your turn. Fill in the ___ , then run and compare.

Define an interface with one abstract method and one default method, then implement it.

📋 Quick Reference — Interfaces & Abstract Classes

Practice quiz

An interface method with no body is…

  • abstract — implementers must provide it
  • a default method
  • a private method
  • automatically static

Answer: abstract — implementers must provide it. A method without a body is abstract; every implementer must supply it.

What is a default method in an interface?

  • A method that returns null
  • A method with a body that implementers inherit for free
  • A method that cannot be overridden
  • The first method declared

Answer: A method with a body that implementers inherit for free. A default method provides a body that implementers inherit unless they override it.

What restriction applies to properties declared in an interface?

  • They must be private
  • They must be var
  • They cannot store a value in a backing field
  • They must be nullable

Answer: They cannot store a value in a backing field. Interface properties must be abstract or computed — no backing field/stored value.

Which keyword is required when implementing an interface member?

  • open
  • implement
  • super
  • override

Answer: override. Implementing an interface member requires the override keyword.

How many interfaces can a single class implement?

  • As many as needed
  • Exactly one
  • At most two
  • None

Answer: As many as needed. A class can implement many interfaces, though it extends only one class.

If two interfaces supply the same default method, what must the class do?

  • Ignore both
  • Override it and disambiguate the super call
  • Delete one interface
  • Nothing — Kotlin picks one

Answer: Override it and disambiguate the super call. The class must override the method and pick which default via super<Interface>.

What does super<Swimmer>.move() do?

  • Creates a new Swimmer
  • Calls the Swimmer interface's default move()
  • Makes move() abstract
  • Returns null

Answer: Calls the Swimmer interface's default move(). It calls the move() default implementation specifically from the Swimmer interface.

What can an abstract class do that an interface cannot?

  • Declare abstract methods
  • Provide default method bodies
  • Be a supertype
  • Hold stored state and have a constructor

Answer: Hold stored state and have a constructor. Abstract classes can store real properties and run a constructor; interfaces cannot.

When should you prefer an interface over an abstract class?

  • When you need shared stored state
  • When you want to mix several independent capabilities
  • When you need a constructor
  • When you need a backing field

Answer: When you want to mix several independent capabilities. Interfaces compose freely, so prefer them for mixing multiple capabilities.

Which is a valid interface property?

  • val count: Int = 5
  • val ready: Boolean get() = true
  • private var x = 0
  • lateinit var s: String

Answer: val ready: Boolean get() = true. A computed property with a getter is allowed; a stored value with a backing field is not.