两个接口中有同名的方法,用一个类同时实现这两个接口时,如何区分到底调用的是哪个接口的哪个方法了?
package four;public interface ITest
{
void aa();
}public interface IITest
{
void aa();
}public class Test implements ITest, IITest
{
public void aa()
{
}
}
package four;public interface ITest
{
void aa();
}public interface IITest
{
void aa();
}public class Test implements ITest, IITest
{
public void aa()
{
}
}
public String t(){
return "t ";
}
public static void main(String args[]){
ITest1 t1 = new ITestM();
System.out.println(t1.t());
ITest2 t2 = new ITestM();
System.out.println(t2.t());
ITestM tm = new ITestM();
System.out.println(((ITest1)tm).t());
System.out.println(((ITest2)tm).t());
}
}interface ITest1{
String t();
}interface ITest2{
String t();
}输出:
t
t
t
t 不过..这有什么意义?为什么不自己写代码测试一下呢..
2 如果2个接口实现的东西不一样,那我只能说,你的设计结构有问题。