# Abstract Class vs Interface

URL: https://softwaredictionary.org/compare/abstract-class-vs-interface
Last updated: 2026-10-06

In short: An abstract class shares code and state with its subclasses; an interface only declares what a type can do, and a class can implement many.

## What is the difference between an abstract class and an interface?

An abstract class is a class that can't be instantiated on its own; it exists to be extended. It can hold fields, a constructor and fully written methods, next to abstract methods that have no body and must be written by each subclass. An interface is a named contract: a list of method signatures, and sometimes properties, that a type promises to provide, with no state of its own.

The essential difference is that an abstract class shares how related types work, while an interface describes what a type can do. In Java, C# and TypeScript a class can extend only one class but implement many interfaces, so an abstract class fixes a type's place in one family, while interfaces can be combined freely: a `Circle` can be both `HasArea` and `Printable`. Abstract classes suit the template method pattern, where a base class writes `describe()` once and leaves `area()` to each subclass.

The two often work together. A common design defines the contract as an interface and adds an abstract class that implements part of it as a convenient base, as Java does with the `List` interface and the `AbstractList` class. Other code depends only on the interface, so any implementation, including a fake in tests, can be passed in, while related implementations still share code through the abstract class.

A common misconception is that the difference disappeared when Java 8 and C# 8 let interfaces contain default method bodies. Instance fields and constructors still belong only to classes, and a class can still extend just one. Languages also differ: TypeScript interfaces vanish after compilation, while Python has no interface keyword and uses abstract base classes from `abc` or `typing.Protocol` instead.

| Aspect | Abstract Class | Interface |
| --- | --- | --- |
| Purpose | Shares code and state among related classes | Describes what a type can do |
| Per class | One (in Java, C# and TypeScript) | As many as needed |
| Methods | Abstract methods plus fully written ones | Signatures; default bodies since Java 8 and C# 8 |
| Fields | Instance fields with their own values | No instance state; at most constants or property declarations |
| Constructor | Yes, called by subclasses through `super` | No |
| Member access | Can use `protected` and `private` members | Members are public by default |
| Relationship | is-a: a `Circle` is a `Shape` | can-do: a `Circle` is `Printable` |
| In TypeScript at runtime | Compiles to a real JavaScript class | Erased; exists only for type checking |

## Choose Abstract Class when

- Related classes share real code or fields, not just method names.
- A base class should fix the steps of an algorithm and let subclasses fill some in.
- Subclasses need a shared constructor or `protected` helpers.

## Choose Interface when

- Unrelated classes should offer the same ability, such as being comparable or printable.
- A class needs to fulfill several contracts at once.
- You want to swap implementations, for example a fake in tests.
- You only need to describe the shape of an object or an API.

## Frequently asked questions

**Can a class extend an abstract class and implement interfaces at the same time?**

Yes. In Java or TypeScript you write `class Circle extends Shape implements Printable`: one base class, plus any number of interfaces.

**If interfaces can have default methods, why use an abstract class?**

Because interfaces still can't hold instance fields or constructors. When related classes share state, setup logic or `protected` helpers, an abstract class is the place for it.

**Does Python have interfaces?**

Not as a keyword. Abstract base classes from the `abc` module play that role, and `typing.Protocol` describes interfaces that type checkers match by shape, as in TypeScript and Go.

---

Software Dictionary: https://softwaredictionary.org/ · https://softwaredictionary.org/llms.txt
