2008年2月2日 星期六

Nest Interface在member attrib視為static Nest type attrib而member method則須經繼承後才可使用

class NestInterface{
  interface I{
    String STR="nest interface member attrib";
    void fun();
  }
  public static void main(String[] args){
    System.out.println(NestInterface.I.STR);
    //NestInterface.I.fun();   
    //^==不能使用因fun()尚未定義
    C c=new C();
    c.fun();
  }
}
class C implements NestInterface.I{
  public void fun(){
    System.out.println( "nest interface member method");
  }
}
//===================================
interface NestInterface2{
  interface I{
    String STR="nest interface member attrib";
    void fun();
  }
}
class C implements NestInterface2.I{
  public void fun(){
    System.out.println( "nest interface member method");
  }
  public static void main(String[] args){
    System.out.println(NestInterface2.I.STR);
    C c=new C();
    c.fun(); 
  }
}

沒有留言: