【发布时间】:2016-08-12 13:51:24
【问题描述】:
package chap8;
interface Interfaces
{
void nMethod(); // normal method of interface
default void dMethod() // default method of interface
{ System.out.println("Default Method of Interface"); }
static void sMethod() // static method of interface
{ System.out.println(" static method of interface"); }
}
class IClass implements Interfaces
{
public void nMethod()
{ System.out.println("Normal Method of Interface in IClass ");}
static void sMethod()
{ System.out.println("Does function overrided ?");}
public void dMethod()
{ System.out.println("default Method of Interface in IClass ");}
}
class MainClass
{
public static void main(String args[])
{
IClass ob =new IClass();
ob.nMethod();
ob.sMethod(); // overrided method ??
ob.dMethod();
// calling static
//Interfaces.sMethod // via Interfaces
// IClass.sMethod(); // via IClass (why all these sMethod calling showing error)
}
}
问题:a) 接口中声明的 sMethod 是否存在于 IClass 中被 sMethod 覆盖?
b) 为什么我无法通过 Interface 和 IClass 调用 sMethod?
感谢 fpr 帮助!!!
【问题讨论】:
标签: java methods interface static overriding