Skip to content
Learn Netverks

Lesson

Step 14/36 39% through track

inheritance-kotlin

Inheritance

Last reviewed May 28, 2026 Content v20260528
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
beginner

This lesson

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

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

You will apply Inheritance 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 classes are final by default—unlike Java where classes are open unless marked final. Use open on the base class and override on members to customize behavior.

open, override, and super

open class Animal(val name: String) {
    open fun speak() = "$name is quiet"
}

class Dog(name: String) : Animal(name) {
    override fun speak() = "$name says woof"
}

Primary constructor parameters from the base class are passed in the derived header: class Dog(name: String) : Animal(name).

Important interview questions and answers

  1. Q: Why final by default?
    A: Encourages composition over fragile inheritance—explicit open documents extension points.
  2. Q: override keyword required?
    A: Yes for overriding; base members intended for override must be marked open.

Self-check

  1. What keyword makes a class inheritable?
  2. How do you call the superclass implementation?

Tip: Favor composition and interfaces over deep inheritance—same guidance as Java design.

Interview prep

open keyword?

Required on class and members to allow override.

Primary constructor in subclass?

Pass base args: class Dog(name) : Animal(name).

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

  • open keyword?
  • Override rules?

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