===============================[color=red]接口冲突问题[/color]==============================
=================================[color=red]重载模糊问题[/color]===============================
interface Ainterface {
public String say();
}
interface Binterface {
public int say();
}
/**
* 接口冲突的问题(不能被解决的问题)
* @author Ericy
* @version 1.0
*/
public class Interface implements Ainterface, Binterface {
// 提示错误一:The return type is incompatible with B.say()
// -->返回类型和B.say()方法不兼容
// 提示错误二:Duplicate method say() in type Interface
// -->在Interface类型中say()方法重复了
// 因为返回值类型不包含在方法的重载的范围内(方法重载:形式参数类型、个数、顺序的不同)
@Override
public String say() {
// TODO Auto-generated method stub
return null;
}
@Override
public int say() {
// TODO Auto-generated method stub
return null;
}
}
=================================[color=red]重载模糊问题[/color]===============================
interface A {}
interface B {}
/**
* C类实现A接口和B接口
* @author Ericy
* @version 1.0
*/
class C implements A, B {}
class D {
/**
* say(...)方法重载
* @param a A类型的参数
*/
public void say(A a) {
System.out.println("A");
}
/**
* say(...)方法重载
* @param b B类型的参数
*/
public void say(B b) {
System.out.println("B");
}
}
/**
* 重载模糊的问题(是可以被解决的问题)
* @author Ericy
* @version 1.0
*/
public class Overload {
public static void main(String[] args) {
D d = new D();
C c = new C();
// 这就是重载出现模糊的地方,编译器不知道要怎么识别c对象到底是A类型的还是B类型的。
// 解决该问题:你就必须告诉编译器我当前的这个c对象是A类型还是B类型的。
d.say((A) c);
d.say((B) c);
}
}