Java / Inheritance
What happens when a class implements two interfaces and both have a method with same name and signature?
This is a valid scenario. If a type implements two interfaces, and each interface define a method that has identical signature, then in effect there is only one method, and they are not distinguishable.
The below snippet compiles and runs.
public interface InterfaceA { void method1(); } public interface InterfaceB { void method1(); } public class ClassImplementing2Interface implements InterfaceA,InterfaceB { @Override public void method1() { System.out.println("hello from method1"); } public static void main(String[] args) { new ClassImplementing2Interface().method1(); } }
Output:
hello from method1
More Related questions...