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