如果有两个接口有个相同的事件,那我实现的时候怎么区分呢?比如interface X1
{
void show();
}
interface X2
{
void show();
}class TestInterface implements X1,X2
{
void show()
{
//实现
}
}
{
void show();
}
interface X2
{
void show();
}class TestInterface implements X1,X2
{
void show()
{
//实现
}
}
interface IX1
{
void show();
void pop();
}interface IX2
{
void show();
void push();
}interface IY extends IX1,IX2
{
void list();
}class TI implements IY
{
public void list()
{
//实现list
}
public void show()
{
//实现show?????????????
}
public void pop()
{
//实现pop
}
public void push()
{
//实现push
}
}class TestI
{
public static void main(String[] args)
{
TI ti = new TI();
}
}
public interface IF1 {
void test();
}public interface IF2 {
void test();
}public class IFimpl implements IF1, IF2 {
public void test() {
System.out.println("test()");
}
}public class IFtest {
public static void main(String[] args) {
IF1 t1 = new IFimpl();
t1.test();
IF2 t2 = (IF2) t1;
t2.test();
}
}
一楼说的也不对啊,编译可以通过 啊 没有报错 但不知道是实现的那个接口的show()方法
void test();
}public interface IF2 {
void test();
}public class IFimpl implements IF1, IF2 {
public void test() {
System.out.println("test()");
}
}public class IFtest {
public static void main(String[] args) {
IF1 t1 = new IFimpl();
t1.test();
IF2 t2 = (IF2) t1;
t2.test();
}
}
完全正确
interface X1
{
void show();
}
interface X2
{
void show();
}class TestInterface implements X1,X2
{
void X1.show()
{
//实现
}
void X2.show()
{
//实现
}}
这应该是最简结的表达方式了