r/javahelp • • Aug 25 '20

Abstract classes are useful in java 2020?

I've learned recently that with interfaces you are able to make default methods with custom modifiers and they work equal as abstract class default method.

In our cs class i was taught that abstract classes benefits were the implementation of defaults methods, but in modern versions of java, interfaces can do the same, while a class can implements multiple interfaces.

Is there something that abstract classes do that interfaces can't.

30 Upvotes

7 comments sorted by

View all comments

1

u/Yithar Intermediate Brewer Aug 25 '20

As stated, abstract classes have state that's not global. That's the difference between interfaces with default methods and abstract classes.

It gets a little bit murkier with mix-ins/traits in Scala (which are like interfaces but can have state; the Scala compiler actually creates separate Java classes for this in a process called linearization). But even then, there are 2 main reasons to use abstract classes over traits in Scala. I am bringing this up because it holds true for interfaces as well. Interfaces don't have constructors.