·
🚀 Java Interview Questions – Episode 3
💡 What’s the difference between an abstract class and an interface?
📌 In Java:
🟣 Abstract class can have both abstract and non-abstract methods.
🟣 Interface used to only declare methods... but since Java 8, interfaces can now have default and static methods with implementations!
🧠 When to use what?
🔸 Use an interface when you're defining a contract or capability that can apply to unrelated classes (e.g. Comparable, Serializable).
🔸 Use an abstract class when you want to share common base behavior or state across related classes (e.g. having fields, constructors, and method implementations).
Think:
✅ Interface = What it can do
✅ Abstract class = What it is