Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (5.3k points)

as Java 8 allows for default implementation of methods in interface called Default Methods, there seems to be a confusion between when would I use a abstract class

So when should interface with default methods be used and when should an abstract class be used? Are the abstract classes still useful in that scenario?

1 Answer

0 votes
by (9.5k points)

 you should go with the default method in the interface.

The constraint on the default method is that it can be implemented only in the terms of calls to other interface methods, with no reference to a particular implementation's state. So the main use case is higher-level and convenience methods.

The good thing about this new feature is that, where before you were forced to use an abstract class for the convenience methods, thus constraining the implementor to single inheritance, now you can have a really clean design with just the interface and a minimum of implementation effort forced on the programmer.

Related questions

0 votes
1 answer
0 votes
1 answer
asked Oct 17, 2019 in Java by Shubham (3.9k points)
0 votes
1 answer
asked Sep 26, 2019 in Java by Shubham (3.9k points)

Browse Categories

...