|
|
Re: Interfaces
|
Posted: Aug 13, 2009 1:51 AM
|
|
> Hi, Could someone help me on this. > > Interface A { String test(): } > Interface B { int test():} > > I want an Interface C to implement both A and B. > How can I do it programatically in java.
You cannot implement two methods in the same class with the same signature. These two methods have the same signature. The return type is not part of the signature, just the method name and parameter list. Therefore, there is no way to achieve what you want, without changing one or both of the method names (or changing the return types so that both the test methods return the same type).
public interface A { String testA(); }
public interface B { int testB(); }
public interface C extends A, B {}
public class D implements C // (or implements A, B (as C is not needed))
{
@Override public String testA() { return "1"; }
@Override public int testB() { return 1; }
}
orpublic interface A { int test(); }
public interface B { int test(); }
public interface C extends A, B {}
public class D implements C // (or implements A, B (as C is not needed))
{
@Override public int test() { return 1; }
}
|
|