Interview replay

Full round replay — abstract vs interface

10 minintermediate110 yrs

Timed verbal replay with pass/fail criteria per follow-up.

How to run this

Answer out loud, timed. Do not read the entry first. Then compare against "The Answer" and "Interviewer's Next Move" and mark yourself.

The opener

When do you choose an abstract class over an interface?

Budget: 45 seconds. Going long here is itself a fail signal.

Follow-ups

  1. 1. “Can an interface have state?

    Testing: The main difference that actually survived Java 8.

    Scoring

    Pass: No instance state. Every interface field is implicitly public static final — one shared constant, not per-instance data — which is why a default method has no fields to work with.

    Fail: 'Yes, you can declare fields' without knowing they are constants.

  2. 2. “What problem do default methods solve, and what did they reintroduce?

    Testing: Library evolution, then multiple inheritance of behaviour.

    Scoring

    Pass: Adding a method to a published interface used to break every implementor — which is why Collection.stream() could not exist. They reintroduced multiple inheritance of behaviour; conflicting defaults are a compile error resolved with Interface.super.

    Fail: 'To avoid writing the method in every class' — a consequence, not the reason.

  3. 3. “Does Java have multiple inheritance?

    Testing: Behaviour vs state — the distinction is the whole answer.

    Scoring

    Pass: Of behaviour since 8, not of state. The classic diamond problem is about duplicated fields, and interfaces cannot hold fields, so the hard case cannot arise.

    Fail: A flat 'no'.

  4. 4. “A class extends a base with summary() and implements an interface with a default summary(). Which runs?

    Testing: The class always wins — and that it is silent.

    Scoring

    Pass: The class's, by the 'class always wins' rule, which exists so adding a default can never change an existing class's behaviour. Notes it compiles with no warning, which makes it a real trap.

    Fail: 'The interface, it's more specific' or 'ambiguous, it won't compile'.

  5. 5. “Can a default method override equals or toString?

    Testing: Do they connect it to the previous answer?

    Scoring

    Pass: No, compile error. Everything inherits those from Object and the class always wins, so a default could never be reached — allowing it would be declaring dead code.

    Fail: 'Yes, why not?'

  6. 6. “You're designing a public API and genuinely cannot decide. What ships?

    Testing: Judgement and awareness of the cost to implementors.

    Scoring

    Pass: The interface, with an abstract base beside it if implementors want one. It does not spend their single extends, it can be a lambda target, and the JDK does exactly this with List and AbstractList.

    Fail: 'Abstract class, it's more powerful.'

Score yourself

6/6 — you can hold this topic at senior level 4-5 — solid; reread "Interviewer's Next Move" 0-3 — reread "Understand It" and redo the Challenge tier

← Back to When do you choose an abstract class over an interface?