Autocoder

Java Interfaces and Abstract Classes Interview Questions

Last updated 2026-11-19

Abstract class versus interface is asked in almost every Java interview, and the answer has changed since Java 8 gave interfaces default methods. A good answer today covers state, constructors, inheritance rules, default-method conflict resolution and the design reason to choose one over the other.

The questions below move from definitions to the corner cases interviewers like: which method wins when a class and an interface both define one, why equals cannot be a default method, and when an abstract class can have no abstract methods. The broader OOP rules are on the Java OOP page.

Interface membersConstants, abstract, default, static and private methods
Abstract class membersAny, including state and constructors
Java version17 and later

Quick comparison

Java Interfaces and Abstract Classes Interview Questions: questions with worked answers

  1. 1

    What are the main differences between an interface and an abstract class today?

    easy

    An abstract class can declare instance fields, constructors and methods of any visibility, but a class can extend only one. An interface can declare only constants and no instance state, supports default, static and private methods, and a class can implement any number. Both cannot be instantiated directly. Pick an abstract class when subclasses share state and a base implementation, and an interface when you define a role that unrelated types can play.

  2. 2

    What are default methods and why were they added?

    medium

    A default method has a body inside an interface, marked with the default keyword. They were added in Java 8 so existing interfaces such as Collection could gain methods like stream() and forEach without breaking every implementing class. Implementers inherit the default but may override it.

    java
    interface Greeter {
        String name();
        default String greet() { return "Hello, " + name(); }
    }
    Greeter g = () -> "Asha";
    System.out.println(g.greet());   // Hello, Asha
  3. 3

    What does this print? A class method and an interface default with the same signature.

    hard

    The class always wins: a method inherited from a superclass takes precedence over an interface default. This "class wins" rule is checked before any interface-versus-interface conflict. Here the call prints Base.

    java
    interface I { default String name() { return "I"; } }
    class Base { public String name() { return "Base"; } }
    class D extends Base implements I { }
    System.out.println(new D().name());   // Base
  4. 4

    Two interfaces provide the same default method. What happens?

    medium

    The class implementing both does not compile unless it overrides the method. Inside the override you can pick one with InterfaceName.super.method(). If one interface extends the other, the more specific interface wins without any conflict.

    java
    interface A { default String hi() { return "A"; } }
    interface B extends A { default String hi() { return "B"; } }
    class C implements A, B { }
    System.out.println(new C().hi());   // B  (B is more specific than A)
  5. 5

    Can an interface have static and private methods? How are they called?

    medium

    Yes. A static interface method belongs to the interface and is called as Interface.method(); it is not inherited by implementing classes or called through an instance. A private method (Java 9) lets default and static methods share helper code without exposing it. Fields are implicitly public static final, so they are constants and cannot be reassigned.

    java
    interface Util {
        static int twice(int x) { return helper(x) * 2; }
        private static int helper(int x) { return x; }
    }
    System.out.println(Util.twice(4));   // 8
  6. 6

    Can an abstract class have a constructor and can it have no abstract methods?

    medium

    Yes to both. The constructor runs when a concrete subclass is instantiated, through super(...), and is how the abstract class initialises its fields. An abstract class with no abstract methods simply prevents direct instantiation; this is used for base classes that are meant to be extended, such as adapters. You cannot call new on it, but new Base() { } with a body creates an anonymous concrete subclass.

  7. 7

    Which modifier combinations are illegal with abstract?

    easy

    abstract cannot combine with final (a final class cannot be extended and a final method cannot be overridden), private (not visible to subclasses so it can never be implemented), or static (static methods are bound to the class, not overridden). A class declared abstract may not be final, and an abstract method cannot have a body.

  8. 8

    Explain the Template Method pattern using an abstract class.

    medium

    The base class defines the skeleton of an algorithm in a final method and leaves variable steps as abstract methods for subclasses. The skeleton cannot be changed, only the steps can, which is why frameworks use it for things like request handling.

    java
    abstract class Report {
        public final void generate() { load(); format(); System.out.println("done"); }
        protected abstract void load();
        protected abstract void format();
    }
    class Csv extends Report {
        protected void load() { System.out.println("load csv"); }
        protected void format() { System.out.println("format csv"); }
    }
    new Csv().generate();   // load csv, format csv, done
  9. 9

    What is a marker interface and what replaced it?

    medium

    A marker interface has no methods and only tags a class, for example Serializable, Cloneable and RandomAccess. The JVM or library checks it with instanceof. Annotations such as @FunctionalInterface or custom ones now cover most such needs because they can carry parameters, but marker interfaces still give a compile-time type that can be used as a parameter type.

  10. 10

    Why can an interface not provide a default equals, hashCode or toString?

    hard

    The compiler rejects defaults that override Object public methods, because a class always inherits a concrete implementation from Object, and class implementations beat interface defaults under the class-wins rule, so such a default could never be used. Interfaces can still redeclare the methods abstractly to document a contract, as Comparator does with equals.

  11. 11

    What is a functional interface and how does it relate to abstract methods?

    medium

    An interface with exactly one abstract method is a functional interface and can be the target of a lambda. Methods inherited from Object, such as equals, do not count, and default or static methods do not either. Comparator is functional even though it declares equals. The @FunctionalInterface annotation makes the compiler enforce the rule. See streams and lambdas.

  12. 12

    How do sealed interfaces fit in?

    medium

    A sealed interface or class declares which types may implement or extend it, with permits (inferred if they are in the same file). Permitted subtypes must be final, sealed or non-sealed. This gives a closed hierarchy that the compiler can check for exhaustive switch coverage, a middle ground between an open interface and an enum.

    java
    sealed interface Payment permits Card, Upi {}
    record Card(String no) implements Payment {}
    record Upi(String id) implements Payment {}
  13. 13

    Can an enum implement an interface? Can an interface extend several interfaces?

    medium

    An enum may implement interfaces, and each constant can even provide its own method body, which makes it a neat strategy pattern. An enum cannot extend a class because it already extends java.lang.Enum. An interface can extend any number of interfaces, which is the only form of multiple inheritance of type in Java.

    java
    enum Op implements java.util.function.IntBinaryOperator {
        ADD { public int applyAsInt(int a, int b) { return a + b; } },
        MUL { public int applyAsInt(int a, int b) { return a * b; } }
    }
    System.out.println(Op.MUL.applyAsInt(3, 4));   // 12
  14. 14

    How do you evolve a published interface without breaking implementers?

    medium

    Add the new method as a default method with a sensible implementation, which keeps old classes compiling and working. Adding an abstract method breaks every implementer. For larger changes create a new interface that extends the old one. With abstract classes you can add a concrete method safely but at the cost of the single-inheritance slot.

  15. 15

    Which should you choose when designing an API: abstract class or interface?

    hard

    Default to an interface for the public contract, because it is flexible, mockable and does not consume the implementer's single inheritance slot. Provide an optional abstract skeleton class (like AbstractList for List) that implements the common logic, so implementers can choose. Use an abstract class alone only when you need protected state, constructors or non-public members shared by a closely related family.

Frequently asked questions

Can an interface have a constructor?

No. Interfaces have no instance state to initialise, so they have no constructors.

Can I instantiate an interface?

Not directly, but you can create an anonymous class or a lambda that implements it.

Is multiple inheritance supported in Java?

Of type, yes, through interfaces. Of state, no, since a class extends only one class.

Does an abstract class need at least one abstract method?

No. The abstract keyword alone stops direct instantiation. Revise Java interview questions for related basics.

Related guides

More in Programming Language Interview Questions by Language

See all in this section