☕ Java Beginner

What is the difference between abstract class and interface in Java?

Why Interviewers Ask This

Foundational questions like this help interviewers calibrate the rest of the interview. A confident, accurate answer signals that you have solid Java basics — a prerequisite for any developer role.

Answer

An abstract class can have constructors, instance variables, and a mix of concrete and abstract methods. A class can extend only one abstract class. Use it when you want to share state and provide partial implementation among closely related classes. An interface cannot have constructors or instance state (only constants). A class can implement multiple interfaces. Use it to define a capability or contract for unrelated classes. Since Java 8, the distinction blurred with default methods in interfaces, but the key difference remains: abstract classes are for "is-a" relationships with shared state, while interfaces are for "can-do" capabilities without state.

Pro Tip

If you're unsure about a detail, say so honestly and explain your reasoning. Interviewers respect candidates who can think through uncertainty rather than bluffing.