When an abstract class needs to implement the interface in Java. Will it be better if all put all the interface methods into the abstract class?
Asked
Active
Viewed 45 times
0
-
Welcome to Stack Overflow. Please take a few minutes to take a tour of the site. After that, if you want to ask a question, please spend some time searching the site to see if you can already find your answer. This question has been asked literally hundreds of times over the past few years. – Tim Biegeleisen Sep 20 '18 at 11:08
-
you can use default methods in interfaces in Java 8. And no, concrete classes might have to implement their own versions of a method so the abstract class doesn't need to implement all. only the once common to its subclasses. – Jack Flamp Sep 20 '18 at 11:09
-
This completely depends on what you are trying to do. There is no "rule" stating that all interface methods should be put into the abstract class. Some of the interface methods could be implemented in the abstract class, and some could be left to be implemented in subclasses of the abstract class. – marstran Sep 20 '18 at 11:10
-
Guys, i understand the differences between interface and abstract class. I just want to know in what cases that we should consider to use an abstract class and implementing the interface without provide any implementation in the abstract class. and in what cases it is better to define all the methods that are going to be implemented by the subclass in the abstract class without using interface at all. I appreciate if someone can give the examples. Thanks – 3wai3 Sep 20 '18 at 17:06