class one
{
void call()
{
System.out.println(" A method");
}
}
class two extends one
{
void call()
{
System.out.println(" B method");
}
}
public class Dispatch{
public static void main(String[] args) {
one a=new one();
two b=new two();
one r;
r=a;
r.call();
r=b;
r.call();
}
}
使用的IDE:VSCode
这是尝试实现运行时多态性的尝试。我使用了“ Java-完整参考-Herbert Schildt”中使用的相同示例,但是它显示了一个错误:
"Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Type mismatch: cannot convert from two to one".
答案 0 :(得分:0)
您的示例在我的机器上编译并运行时没有错误(使用Eclipse)。
一些想法:也许您的IDE设置为仅在手动请求时重新编译(而不是典型的默认连续构建)。也许您的IDE配置了一些奇怪的编译器警告设置。