How many concrete methods can an interface have (JDK 7 and below) JDK 7 and below. I have tried to research everywhere but can not find anything.
2 Answers
Interfaces cannot have any concrete methods. If you need the ability to have abstract method definitions and concrete methods then you should use an abstract class.
Note: This is only true for JDK 7 and lower. JDK 8 includes default methods which provide concrete methods in interfaces. (Thanks EJoshuaS)

- 365
- 3
- 10
-
This is only partially correct. Java 8 has [default methods](https://www.geeksforgeeks.org/default-methods-java/), which is basically what the OP is asking. Java 7 and lower does not. – EJoshuaS - Stand with Ukraine Nov 20 '19 at 17:26
-
thank you. so an interface can not contain concrete methods? – GulfamChoudhary Nov 20 '19 at 17:27
-
@GulfamChoudhary Yes, in JDK 7 and below an interface cannot contain concrete methods. – Connor Nov 20 '19 at 17:28
-
You should edit your answer to specify that that's true for Java 7, because this answer is incorrect for Java 8 and higher. – EJoshuaS - Stand with Ukraine Nov 20 '19 at 17:28
-
@EJoshuaS I'll add a clarification, but I think that distinction is unnecessary because the question specified JDK 7 and lower. – Connor Nov 20 '19 at 17:30
Java 8 has default methods, which is basically what you're asking about. However, Java 7 and lower cannot have that; it can only specify the mandatory method signatures. So, the answer to your question is "none at all - Java 7 doesn't allow that."
There is not, as far as I know, a hard limit on the number of methods that an interface can have. That being said, if you're even asking about this, you likely have a design problem because you're probably considering making your interface too large. A good rule of thumb is that, if you're describing what an interface is for, you shouldn't have to use the word "and" - if you find that you do, you should refactor to split it into multiple interfaces.
Edit: Evidently the maximum is 65535, but there’s no reason that you should ever have anything close to that.

- 11,977
- 56
- 49
- 78