1. Introduction
When you’re just starting to write code, it feels like one class is “one role.” But reality quickly proves otherwise. The same object can simultaneously be “something that can print to the console,” “something that can serialize to CSV,” “something that can be logged,” “something that can be validated.” And if you try to dump everything into one interface EverythingEverywhereAllAtOnce, you won’t get an architecture—you’ll get a buffet of methods.
The key idea: it’s convenient to keep interfaces narrow and topic-focused. Then a class can implement several small contracts at once. Kotlin allows this: class X : A, B, C. The problem appears not because of “multiple” itself, but because contracts sometimes overlap in names and signatures. And that’s where the compiler becomes your strict editor: “In this scene, two actors said the line render() at the same time—who do we listen to?”
Basic Kotlin rule: ambiguity is forbidden
This rule is worth memorizing literally like a road sign.
If a class inherits multiple implementations of the same member (a function or a property) from its immediate supertypes, Kotlin forces you to write override and define the final behavior yourself.
This applies both to the case of “two default implementations” and to the case of “one interface has a default, and the other has only a declaration (abstract).” In Kotlin documentation it’s phrased like this: with multiple inheritance of implementations you must explicitly resolve the ambiguity, and to choose a specific implementation you use a qualified super<...>.
An important mindset: the compiler isn’t being picky. It’s protecting you (and future you) from the magic of “let it pick something somehow.” In languages where these things are “resolved automatically,” legendary bugs show up later and live exactly until the first release.
2. Default method conflict and super<...>
Conflict of two default methods
Let’s imagine two interfaces; both provide a default implementation of the same method ping():
interface A {
fun ping(): String = "A"
}
interface B {
fun ping(): String = "B"
}
Now we want to make a class that implements both:
class C : A, B // <- questions will start here
From Kotlin’s point of view, this is the situation “which ping() are you inheriting?”. If the compiler silently picked one, you’d later be explaining to yourself for a long time why it “sometimes prints A.” That’s why Kotlin will require you to:
- explicitly write override fun ping(),
- and inside it (if needed) choose which implementation to call.
And this is where today’s hero appears: super<InterfaceName>.method().
super<...>: how to say “take the implementation from exactly here”
super without qualification works when inheritance is unambiguous (for example, a regular class extends one base class and there is only one super). But when we have multiple sources of the same method, Kotlin requires a qualifier in angle brackets: super<A>.ping().
Example: “glue” the behavior of two interfaces together:
interface A {
fun ping(): String = "A"
}
interface B {
fun ping(): String = "B"
}
class C : A, B {
override fun ping(): String {
return super<A>.ping() + super<B>.ping()
}
}
fun main() {
val c = C()
println(c.ping()) // AB
}
From a readability perspective this is nice: you open the method and immediately see “the final behavior is a combination of A and B.” No shamanism.
3. Other kinds of conflicts
Default + abstract method: “there seems to be an implementation, but override is still required”
This is the most common “newbie trap.”
Let’s imagine that one interface provides a default implementation, while the second only requires the method (no body):
interface WithDefault {
fun value(): Int = 10
}
interface MustImplement {
fun value(): Int
}
It feels like: “But there’s already a ready-made implementation—what does the compiler want?” But Kotlin sees it differently: both interfaces declared the same member, so the class must explicitly fix what happens.
You write:
class D : WithDefault, MustImplement {
override fun value(): Int = super<WithDefault>.value()
}
fun main() {
val d = D()
println(d.value()) // 10
}
Why is this better? Because MustImplement is the contract “someone must give meaning to value().” If you “silently” get the implementation from WithDefault, a person reading the code might not notice that the class satisfies MustImplement not with its own logic, but by “picking up” someone else’s. Kotlin forces you to make it explicit: either you write your own implementation, or you say “yes, I’m taking the default from WithDefault.”
Conflict between a class and an interface
A “diamond” can happen this way too: there is a base class (with an implementation), and there is an interface (also with an implementation of the same method). Kotlin treats this as two implementations from two sources—so override is mandatory.
Mini example:
open class BaseLogger {
open fun tag(): String = "BASE"
}
interface UiTaggable {
fun tag(): String = "UI"
}
class ScreenLogger : BaseLogger(), UiTaggable {
override fun tag(): String {
return super<BaseLogger>.tag() + "-" + super<UiTaggable>.tag()
}
}
fun main() {
val logger = ScreenLogger()
println(logger.tag()) // BASE-UI
}
A useful habit: when you see class X : SomeClass(), A, B, keep in mind that conflicts are possible not only between A and B, but also between SomeClass and A/B.
Property conflicts: the same logic, just in the form of val
Conflicts are usually discussed for functions, but properties behave similarly, because a property is essentially get() (and sometimes set()).
Let’s imagine:
interface LeftLabel {
val label: String get() = "LEFT"
}
interface RightLabel {
val label: String get() = "RIGHT"
}
class BothLabels : LeftLabel, RightLabel {
override val label: String
get() = super<LeftLabel>.label + "+" + super<RightLabel>.label
}
fun main() {
val x = BothLabels()
println(x.label) // LEFT+RIGHT
}
super<LeftLabel>.label is essentially a getter call from a specific interface. And again: the conflict is resolved with override and an explicit choice of the source.
4. Practical example: formatting expenses in different styles
“Human-readable” and CSV: two contracts, one conflict
Let’s tie the idea to a practical console app (roughly, an expense tracker). At this point in the course, we already have data models (for example, data class Expense) and we periodically print them to the console. Over time, it’s almost inevitable that you’ll want to output the same entity in different formats: “human-readable” and “CSV.”
Let’s create two interface contracts: one for “human” text, the other for CSV. And we’ll intentionally create a conflict: both will provide a default method formatTitle(...), but according to different rules.
data class Expense(
val title: String,
val amount: Int
)
interface HumanFormat {
fun formatTitle(title: String): String =
title.trim().replaceFirstChar { it.uppercase() }
}
interface CsvFormat {
fun formatTitle(title: String): String =
"\"" + title.trim().replace("\"", "\"\"") + "\""
}
Now we want a class that “can do both” (for example, later we’ll choose the format depending on the command mode):
class ExpenseTitleFormatter : HumanFormat, CsvFormat {
override fun formatTitle(title: String): String {
// Choose the rule "for humans"
return super<HumanFormat>.formatTitle(title)
}
}
fun main() {
val f = ExpenseTitleFormatter()
println(f.formatTitle(" coffee ")) // Coffee
}
What matters in this example: a conflict does not mean “you did something wrong.” A conflict means “you have two reasonable formatting rules, but in this particular class you need to make a decision.” And Kotlin forces you to record that decision in code, not in your head.
If you need the CSV rule instead, change one line to super<CsvFormat>.formatTitle(title).
Combining behaviors: when super calls become a new rule
Sometimes the right answer to a conflict is not to pick one implementation, but to combine them by adding a clear rule. For example, a human-readable title, but with a note that this is an “export string.”
interface HumanFormat {
fun formatTitle(title: String): String =
title.trim().replaceFirstChar { it.uppercase() }
}
interface CsvFormat {
fun formatTitle(title: String): String =
"\"" + title.trim().replace("\"", "\"\"") + "\""
}
class MixedTitleFormatter : HumanFormat, CsvFormat {
override fun formatTitle(title: String): String {
val human = super<HumanFormat>.formatTitle(title)
val csv = super<CsvFormat>.formatTitle(title)
return "$human (csv=$csv)"
}
}
fun main() {
val f = MixedTitleFormatter()
println(f.formatTitle(" big \"sale\" ")) // Big "sale" (csv="big ""sale""")
}
Notice: we intentionally create two intermediate vals. This is a bit longer than “in one line,” but noticeably more readable for a beginner and for a tired adult developer on a Friday evening.
5. Cheat sheet: when you need override and what to write inside
When you run into conflicts for the first time, your brain wants a simple cheat sheet. Let’s make a small table. It won’t replace understanding, but it will help you not panic.
| Situation | What happens | What to do |
|---|---|---|
| Two interfaces provide a default for the same method | Two implementations → ambiguity | override + choose/merge via super<A>/super<B> |
| One interface is default, the other declares it abstractly | Kotlin requires explicitness | override + either your own logic, or super<WithDefault> |
| A base class and an interface both implement the method | Two implementations from different supertypes | override + (optional) super<Base> and/or super<Interface> |
| Conflict in a property (val) with a getter | Essentially a getter conflict | override val + choose/merge via super<...>.prop |
6. How to read such override in someone else’s code and not be afraid
When you see something like this in a project:
override fun foo() {
super<A>.foo()
super<B>.foo()
}
don’t take it as “complexity for complexity’s sake.” It almost always has one of three meanings.
The first meaning is “both behaviors matter, we run both.” This often appears in logging, notifications, metrics collection, handler chains. The second meaning is “we choose one implementation, but we want to record that choice explicitly.” Then there will be one super<...> inside. The third meaning is “we don’t trust the defaults and we write our own implementation completely,” and then there may be no super<...> at all.
A useful habit: if you see an interface conflict, ask yourself “what business rule is being applied here?” Look for the answer in the override body—it’s usually written for exactly that reason.
7. Common mistakes with multiple interface implementation
Error #1: expecting Kotlin to “take the first interface in the list.”
Some students, out of habit, think that class X : A, B means “if there’s a conflict, A wins because it’s earlier.” Kotlin does not do that. It intentionally forces you to make a decision via override; otherwise the code would behave too magically and debugging would turn into archaeology.
Error #2: writing super.ping() in a conflict and being surprised it doesn’t work.
When there are multiple implementations, super without qualification doesn’t provide an unambiguous answer, and the compiler won’t let you “guess.” In such cases you need exactly super<A>.ping() or super<B>.ping(). This syntax is not decoration; it’s a way to explicitly point to the implementation source.
Error #3: “gluing” two implementations together without meaning and getting a weird result.
Technically, you can do super<A>.foo(); super<B>.foo() in almost any case, but logically it can be absurd: for example, two implementations may represent different output formats or different policies. If you combine behaviors, make it a conscious rule that can be read from the code (for example, via intermediate vals and a clear result string).
Error #4: missing a conflict because “there seems to be only one implementation.”
The “default + abstract” case is often perceived as “but there is an implementation.” However, Kotlin requires override because the contracts overlap. If you don’t understand why the compiler forces you to override the method, check whether the second interface declares the same method without a body. This is not a bug; it’s readability protection.
Error #5: creating interfaces that are too broad and constantly conflict by name.
If you regularly hit conflicts on methods like print(), render(), format(), it may be a signal that your interfaces are too generic and overlap in meaning. Sometimes it’s enough to rename the method to something more specific (renderCsvLine(), renderHumanLine()) so the code reads better and there are fewer conflicts.
Error #6: trying to hide the conflict with a “universal hack” instead of solving it.
Sometimes you just want “anything that compiles,” so you write an override that returns something random, ignoring both default implementations. The contract is formally satisfied, but the behavior becomes surprising. If interfaces conflict, it almost always means you need to formulate a rule: “we choose A,” “we choose B,” or “we combine them like this.”
GO TO FULL VERSION