Skip to content
Learn Netverks

Lesson

Step 17/36 47% through track

interfaces

Interfaces

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

This lesson

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

Interfaces and polymorphism are central to Spring, testing with mocks, and enterprise design patterns.

You will apply Interfaces 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.

An interface defines a contract—method signatures without necessarily providing bodies (Java 8+ allows default and static methods). Classes implements one or more interfaces.

Example

interface Notifier {
    void send(String message);
}

class EmailNotifier implements Notifier {
    public void send(String message) {
        System.out.println("Email: " + message);
    }
}

Interfaces enable polymorphism without forcing a class hierarchy—similar to TypeScript interfaces or PHP interfaces.

Important interview questions and answers

  1. Q: Interface vs abstract class?
    A: Interface for capability contracts (multiple inheritance of type); abstract class for shared state + partial implementation.
  2. Q: Can interfaces have fields?
    A: Only public static final constants implicitly.

Self-check

  1. How many interfaces can a class implement?
  2. When would you choose an interface over an abstract class?

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

  • Interface vs abstract?
  • default method use?

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