Skip to content
Learn Netverks

Lesson

Step 15/36 42% through track

inheritance

Inheritance

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

This lesson

This lesson teaches Inheritance: the syntax, APIs, and habits you need before advancing in Java.

Teams ship Inheritance on every Java codebase—skipping it leaves gaps in debugging and code reviews.

You will apply Inheritance in contexts like: Spring Boot APIs, banking systems, Android (with Kotlin), and batch/data pipelines on the JVM.

Write Java with a public class (lessons use Main), click Run on server—the dev runner runs javac then java; fix compile errors from stderr (LEARNING_RUNNER_ENABLED=true).

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

Inheritance models "is-a" relationships: class Dog extends Animal. Subclasses inherit fields and methods, can override behavior, and call superclass logic with super.

extends keyword

class Animal {
    void speak() { System.out.println("..."); }
}

class Dog extends Animal {
    @Override
    void speak() { System.out.println("Woof"); }
}

Java supports single inheritance for classes—one direct superclass only. Interfaces provide multiple type contracts.

Important interview questions and answers

  1. Q: extends vs implements?
    A: extends for classes (single); implements for interfaces (multiple allowed).
  2. Q: What is @Override?
    A: Documents intent; compiler verifies a valid override exists.
  3. Q: Composition vs inheritance?
    A: Favor composition ("has-a") when behavior can be delegated without fragile hierarchies.

Self-check

  1. How many classes can a Java class extend?
  2. What keyword calls the parent constructor?

Tip: Favor composition when behavior can be delegated—deep inheritance trees become fragile in large codebases.

Interview prep

extends vs implements?

extends for single class inheritance; implements for one or more interfaces defining behavior contracts.

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

  • extends one class why?
  • super call when?

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