How many interfaces can be implemented by one class in Java

 
 

Infinite if return types of same methods are the same. Because interface has no implementation there is no risk that Java virtual machine will not know which implementation choose to run. Such problem occurs when language allows You to extend more than one class. When You inherit from more than one implementations (classes) there is a risk that in tow different classes from which You are inheriting has the same name for a method. For example:

Class A {	public void doSomethig() {/* … lot of work to do … */ }}Class B {	public void doSomethig() {/* … lot of work to do … */ }}Class C extends A,B { } // prohibited in Java but possible in C++
In such case call for doSomethig() in type C is indeterministic. But if there is no implementation like in this example:
Interface A { public void doSomething(); }Interface B { public void doSomething(); }Class C implements A,B {	public void doSomething() {/* … lot of work to do … */}
Compiler has no problem which method to call because there is only one for which implementation is provided, the one in class C. But if both interfaces defines same methods but with different return type it is impossible to implement both because methods can`t differ only by their return type:
Interface A { public void doSomething(); }Interface B { public int doSomething(); }Class C implements A,B {	public void doSomething() {/* … lot of work to do … */}
Compilation fails due to: InterfaceCollision But:
Interface A { public void doSomething(); }Interface B { public int doSomething(int argument); }Class C implements A,B {	public void doSomething() {/* … lot of work to do … */}
Compiles fine thanks to method overloading. Now compiler can recognize doSomething method by its arguments.