r/learnjava • u/uniqueUsername_1024 • Dec 22 '25
What is the semantic difference between an interface and an abstract class?
I understand the mechanics—interfaces support multiple inheritance, abstract classes can declare instance variables and override Object methods, etc. However, I don't understand what it means to call something one or the other, especially because default methods exist.
In short: if I declare abstract class Foo, what am I saying about the nature of all Foos? Critically, how does that change if I declare interface Foo instead?
42
Upvotes
View all comments
Show parent comment
0
u/spacey02- Dec 22 '25
I personally wouldn't call the design of a hierarchy where subclasses may not want to support the superclass functionality, like unmodifiable lists throwing runtime errors on .add() instead of compile time errors, a good example of using interfaces. This breaks the whole idea of interface as an implementation contract. Moreover, having 3 different kind of lists in relation to addition elements is a weird choice in my view, especially since performance wasn't really the top concern for the design of java (see Hashtable and Vector).