In Java this is valid
interface Iface1{
void func();
}
interface Iface2{
void func();
}
class Demo implements Iface1, Iface2 {
public void func(){
}
}
but why is this not valid
interface Iface1 {
void func(Integer a);
}
interface Iface2 {
void func(Object a);
}
class Demo implements Iface1, Iface2 {
public void func(Integer a) {
}
}
In this case, since I implement Iface1, the contract of both Iface1 and Iface2 are fulfilled. Since Integer is a subclass of Object.
The compiler gives me error – Class ‘Demo’ must either be declared abstract or implement abstract method ‘func(Object)’ in ‘Iface2’
I was expecting this should work by only implementing the function with parameter Integer type
>Solution :
Iface2 declares func to accept any Object, so to implement that interface, a class must provide an implementation of func accepting any Object. For instance, the call demoInstance.func("this is a string") must be valid.
Demo‘s func only accepts Integers so it does not implement the interface.
In your first setup, the signature of both methods is the same in both interfaces, so there’s a valid implementation for either in Demo.