What is the difference between an interface and an abstract class?
Why Interviewers Ask This
This question tests conceptual clarity. Interviewers want to hear a precise, confident definition before moving to more complex OOP Concepts topics. It also reveals how well you can explain technical ideas to non-experts.
Answer
Both define contracts and cannot be instantiated directly, but they serve different purposes with key differences: Abstract class: can have both abstract (unimplemented) and concrete (implemented) methods; can have instance variables with state; can have constructors; a class can extend only ONE abstract class (single inheritance in Java/C#); use when sharing code among closely related classes: abstract class Animal { protected String name; // State public Animal(String name) { this.name = name; } // Concrete method -- shared behavior: public void breathe() { System.out.println(name + " breathes"); } // Abstract -- each animal speaks differently: public abstract void speak(); } class Dog extends Animal { public Dog(String name) { super(name); } public void speak() { System.out.println(name + " says Woof!"); } }. Interface: all methods are public and abstract by default (before Java 8 default methods); can only have constants (public static final fields — no instance variables); no constructors; a class can implement MULTIPLE interfaces; models "can-do" capabilities across unrelated classes: interface Flyable { void fly(); default void land() { System.out.println("Landing..."); } } interface Swimmable { void swim(); } class Duck extends Animal implements Flyable, Swimmable { public Duck(String name) { super(name); } public void speak() { System.out.println(name + " quacks"); } public void fly() { System.out.println(name + " flies"); } public void swim() { System.out.println(name + " swims"); } }. Rule of thumb: Abstract class = "is-a" relationship, shared implementation; Interface = "can-do" capability, contract definition.
Pro Tip
Before answering, structure your response: one-line definition → real-world analogy → concrete example from a project. This makes even complex OOP Concepts answers easy to follow.