Return to site

Whatโ€™s the difference between an abstract class and an interface?

August 4, 2025

๐Ÿš€ 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