我研究过在实例方法的情况下,在运行时jvm使用实际的实例类,在类方法的情况下,编译器只会查看引用变量的声明类型而不是实际的类.
我研究了这个概念实例方法隐藏..
在我的proram中,我使用了接口引用变量来存储类的对象,并尝试使用它来访问类的实例方法,但它引发了错误.我的程序如下:
interface A
{
void show();
}
class B implements A
{
public void show()
{
System.out.println("Interface Method");
}
void info()
{
System.out.println("IN Info");
}
}
class interDemo
{
public static void main(String args[])
{
A a;
B b=new B();
a=b;
a.show();
a.info();
}
}
Run Code Online (Sandbox Code Playgroud)
请帮我理解一下...