Quick revision
The short answer
A class can implement many interfaces but extend only one class. Interfaces cannot have instance fields or constructors, while abstract classes can hold state, enforce construction and use any access level; since Java 8 interfaces can also have default and static methods, and since Java 9 private methods, but their other members are always public. We choose an interface to describe a type or capability, and an abstract class when implementations share state and a template method with protected hooks.
What to remember
In this answer, we saw that a class can implement many interfaces but extend only one class, that interfaces have no instance fields or constructors and only public members apart from private helpers, and that since Java 8 and 9 they can carry default, static and private methods. Abstract classes can hold state, enforce construction and use protected hooks. We choose an interface for a type or capability and an abstract class for shared state and a template method, and often pair the two.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
A class can implement many interfaces but extend only one class. Interfaces cannot have instance fields or constructors, while abstract classes can hold state, enforce construction and use any access level; since Java 8 interfaces can also have default and static methods, and since Java 9 private methods, but their other members are always public. We choose an interface to describe a type or capability, and an abstract class when implementations share state and a template method with protected hooks.
Background to this question
Default methods blurred the old textbook line that interfaces have no code and abstract classes do, so this question checks whether our understanding is up to date. In real work the choice decides how flexible an API is for other teams: an abstract class uses up their single superclass, while an interface fits into any hierarchy. In this answer, we will recap both constructs, compare what each can contain, look at a template method example that needs an abstract class, and finish with a simple way to choose.
1A Quick Recap of Both Constructs
An interface declares a type: a set of methods that implementing classes promise to provide. A class implements it with implements, and one class can implement as many interfaces as it likes. An abstract class is a class that cannot be instantiated directly and may leave some methods abstract, without a body, for subclasses to fill in. A class extends it with extends, and since Java has single inheritance of classes, it can extend only one.
Both let us write code against a general type and supply the specifics later. The differences are in what they can hold and how many a class can have.
2What Each One Can Contain
The table summarises the rules in current Java. The most important line is the first one about state: an interface can only have constants, which are implicitly public static final, while an abstract class can have ordinary instance fields.
| Feature | Interface | Abstract class |
|---|---|---|
| Instance fields | No, only public static final constants | Yes, any |
| Constructors | No | Yes, can enforce required arguments |
| Method bodies | default, static (Java 8), private (Java 9) | Any method |
| Access levels | Public, except private methods | public, protected, package, private |
| How many per class | Many | One |
Can override equals/hashCode | No, not as a default method | Yes |
3An Interface for a Type or Capability
Interfaces are the natural way to describe what something can do, especially when unrelated classes might want to do it. Comparable, AutoCloseable and Runnable are capabilities that classes from any hierarchy can add.
SmsNotifier already extends TelecomClient, and it can still be a Notifier and an AutoCloseable. If Notifier had been an abstract class, this class could not use it. That is the main reason public types in a library should usually be interfaces.
4An Abstract Class for Shared State and a Template Method
An abstract class fits when implementations share state and a fixed algorithm, with only some steps varying. This is the template method pattern: the base class defines the overall steps in a final method and calls protected hooks that subclasses implement.
None of this is possible in an interface. The counter and the name are instance state, the constructor forces every subclass to provide a name, run() is final so nobody can skip the counting, and the hooks are protected so they are not part of the public API. A default method could imitate the loop, but it could not hold the counter, could not be final, and would expose the hooks publicly.
5How Default Methods Changed the Choice
Before Java 8, an interface could not contain any code, so even small conveniences forced either duplication in every implementation or an abstract base class. Default methods remove that reason: a sendAll() convenience built on send() can live in the interface itself. Static methods let the interface carry its own factories, and private methods let several defaults share helper code without exposing it.
What default methods did not change is state. A default method can only call other methods of the interface; it has no fields of its own. So the rule of thumb survives in a refined form: behaviour that needs no state can go in the interface, behaviour that needs state belongs in a class.
6Choosing Between Them
Start with an interface whenever the goal is a type that other code depends on, or a capability that unrelated classes may share. Add an abstract class when several implementations really share state, need enforced construction, or follow the same algorithm with a few varying steps. The two also combine well: an interface as the public type, with an abstract class that implements it to help implementers, the way List is paired with AbstractList in the JDK. Then callers depend on the interface, and implementers may use the helper or not.
7Follow-up questions
Can an abstract class implement an interface without implementing its methods?
Yes. An abstract class may leave interface methods unimplemented, and the first concrete subclass must provide them. This is exactly how skeletal implementations such as AbstractList work: they implement most of List and leave a few methods abstract.
Can interfaces have constructors or instance initialisers?
No. An interface is never instantiated, so it has no constructor, and it has no instance fields to initialise. Lambdas and anonymous classes implementing an interface get their own constructors from the generated class, not from the interface.
What about sealed interfaces and sealed abstract classes?
Both can be sealed since Java 17, restricting which types may implement or extend them. The same choice applies: a sealed interface is more flexible and works well with records, which cannot extend classes, while a sealed abstract class can still hold shared state.
8Conclusion
In this answer, we saw that a class can implement many interfaces but extend only one class, that interfaces have no instance fields or constructors and only public members apart from private helpers, and that since Java 8 and 9 they can carry default, static and private methods. Abstract classes can hold state, enforce construction and use protected hooks. We choose an interface for a type or capability and an abstract class for shared state and a template method, and often pair the two.
Open with
The biggest difference is inheritance: a class can implement many interfaces but extend only one class, so an abstract class uses up the implementer's single superclass. The second is state.
Then, if they want more
Interfaces can't have instance fields or constructors, only public static final constants, while an abstract class can hold fields and use its constructor to enforce required arguments.
Since Java 8, interfaces can have default and static methods, and since Java 9 private methods for sharing code between defaults, so the old idea that interfaces contain no code is out of date. But interface members other than private methods are always public, whereas abstract classes can use protected and package-private members.
So I choose an interface when I'm defining a type or a capability that other code depends on, like a Notifier or Comparable, because any class can adopt it regardless of its superclass, and default methods can supply small conveniences built on the abstract methods.
I choose an abstract class when implementations share state and an algorithm: a template method, for example a final run method in an ImportJob that loops over lines, counts imports and calls protected hooks like parse and store. That needs fields, a constructor and protected access, none of which an interface can offer.
Often the best design combines them, an interface as the public type and an abstract skeletal class that implements it, like List and AbstractList.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 8, Java 17, Java 9
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- The Java Language Specification, Java SE 21, Java SE 21 API documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Compare abstract classes and interfaces in modern Java (Java 8 and later). When would...": https://scrivio-interview-library.netlify.app/java/interfaces-and-abstract-classes/56ccbfbbea/
Java fundamentals, question 5 of 16 Back to the path
More in Interfaces and abstract classes