Detailed explanation
An abstract class and an interface both support abstraction: they describe behaviour while allowing concrete classes to supply implementations. Neither can be instantiated directly. The main difference is their role in a design. An abstract class provides a shared base with state and implementation for closely related classes. An interface defines a contract that different classes can implement, even when they belong to unrelated class hierarchies. For example, Plane can extend Vehicle while implementing Flyable, separating its base identity from its flying capability.
An abstract class can contain abstract methods, concrete methods, instance fields, static members, and constructors. It may also contain no abstract methods at all. Its constructor runs as part of constructing a subclass object, so it can initialise shared state such as a vehicle identifier. Members can use appropriate access modifiers, including protected for subclass access and private for internal details. A concrete subclass must implement inherited abstract methods unless an implementation is already inherited. Java allows a class to extend only one class, whether that superclass is abstract or concrete.
An interface has no constructors or instance fields. Every interface field is implicitly public, static, and final; a final reference does not make its referenced object immutable. Ordinary interface methods without an implementation are implicitly public and abstract. Since Java 8, interfaces can provide default instance methods and static methods; since Java 9, they can also contain private helper methods. Default methods provide reusable behaviour, but cannot directly store per-object state in the interface. Interface static methods are called using the interface name and are not inherited by implementing classes. A class can implement multiple interfaces, and an interface can extend multiple interfaces.
Interviewers usually expect design reasoning, not just a feature list. Choose an interface when clients need a capability contract and implementations should remain free to extend another class. Choose an abstract class when subclasses genuinely share state, construction rules, or implementation. Both can be combined: Vehicle can centralise shared vehicle logic, while Flyable defines flying operations. In the given example, Plane.fly() must be public because implementing an interface method cannot reduce its visibility.
Key points to remember
- An abstract class supports instance state, constructors, and both abstract and concrete methods.
- An interface has no constructors or instance fields; its fields are implicitly public static final.
- A class extends only one class but can implement multiple interfaces.
- Interfaces support default and static methods from Java 8, and private helper methods from Java 9.
- Use interfaces for capability contracts and abstract classes for shared state and base behaviour.
Common mistakes candidates make
- Claiming interfaces cannot contain method implementations, ignoring default, static, and private methods.
- Implementing an interface method without public visibility, which causes a compilation error.
- Choosing an abstract class solely for code reuse without considering whether the subclasses form a meaningful shared hierarchy.
Likely follow-up questions
What happens if two interfaces provide the same default method?
If neither interface is more specific than the other, the implementing class must override the method to resolve the conflict. Within that override, it can explicitly invoke a directly implemented interface's default implementation using InterfaceName.super.method().
Why does an abstract class need a constructor if it cannot be instantiated?
Its constructor initialises the superclass portion of a concrete subclass object. It runs through the constructor chain before the subclass constructor body executes.
Can an abstract class implement an interface without implementing all its methods?
Yes, an abstract class can leave interface methods unimplemented. A concrete subclass must provide implementations for any remaining abstract methods, and those implementing interface methods must be public.
Interview tip: Start with the contract-versus-shared-base distinction, compare state and inheritance limits, and finish with the Vehicle–Flyable–Plane example.
