0

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 Answers2

1

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)

Connor
  • 365
  • 3
  • 10
0

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.