How many interfaces can a class file implement? Is there a limit on the number of interfaces used by a class file?
4 Answers
For all practical purposes, there is no limit on the number of interfaces a class can implement, but java does not let you inherit from multiple superclasses.
However, if you really want to nitpick, you can say that the number of interfaces a class can implement is bound by the maximum value the interface id can be in java bytecode, or the amount of code memory you have to implement these interfaces, or the amount of hard drive space to store your bytecode. These are silly arguments. Obviously, because your computer doesn't have infinite memory, infinite throughput, and infinite code space, we know that there are theoretical maximums on everything, just like how there's a theoretical maximum number of lines of code you can have in a single jar.
But if you really really want to know the theoretical maximum number of interfaces a class can implement, it's 65535.

- 4,664
- 2
- 27
- 50
-
I've had classes that subclassed more than one class. And it was beautiful. – mre Jun 14 '12 at 13:33
-
Yes, python is a beautiful language. – Hans Z Jun 14 '12 at 13:34
-
@mre I don't think you understand how that's what she said works ಠ_ಠ – Hans Z Jun 14 '12 at 13:42
-
1That's what she also said! :D – mre Jun 14 '12 at 13:42
-
1http://www.youtube.com/watch?v=SAAi_42uIkQ – Hans Z Jun 14 '12 at 13:54
-
@HansZ excellent info! – Gaurav Dec 11 '19 at 09:05
From the Java VM Specification on Limitations of the JVM:
The number of direct superinterfaces of a class or interface is limited to 65535 by the size of the interfaces_count item of the ClassFile structure.
That is the only limitation. And it is due to the structure of the compiled Java bytecode.
-
-
@dacwe Here the limitation is not with the Java language but with the ClassFile specification. – Jivings Jun 14 '12 at 13:43
-
1
The limit is more practical than technical.
A realistic limit is in the dozens for hand written code. For generated code you can have much more, but I suspect you have something wrong with your design if you have that many.
The limit in the file format is 65535.
Given most large projects have less than 10K classes, so it is hard to imagine why you would want to implement that many interfaces in one class.

- 5,965
- 14
- 31
- 57

- 525,659
- 79
- 751
- 1,130
your class can implement unlimited no of Interfaces
and one Interface
can extend unlimited no of Interfaces
but best practice is to don't implement so many interfaces .

- 7,831
- 3
- 35
- 54