Lets say I have two interfaces interface A and interface B:
public interface A {
public int data();
}
public interface B {
public char data();
}
interface A has a method public int data() and interface B has a method public char data().
when I implement both interfaces A and B in some class C the compiler gives me an error. Is this a flaw in java? As I presume this is one of the major reasons why we are not allowed to extend more than one class then why are we allowed to implement more than one interface when this problem still persists?
The Java Tutorials: Defining Methods – Overloading Methods states,
also,
The two implemented methods share a common method signature (i.e.
data()) and as such, the compiler cannot differentiate between the two and will have that single method satisfy both interface contracts.Edit:
For instance,
which will output,