我研究過在實例方法的情況下,運行時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();
}
}
請幫我瞭解conept ...
非常感謝!我的問題就解決了.. – Laawanya 2011-01-08 08:50:39
您可以繼續接受的解決方案,這會是不錯的:)謝謝 – sjr 2011-01-08 19:01:30