请问,如何使用接口中的内部类?

解决方案 »

  1.   

    要看这个内部类是怎么样的内部类,如果是静态内部类,那就可以直接使用,如果不是静态内部类,那就需要外部类的对象来创建内部类对象,又因为外部类是一个借口,不能直接实例化,那么就只能通过实现接口,具体写法有两种,一种是写个类来实现该接口,new 接口实现类类名().new 内部类类名();另外一种是通过匿名内部类来实现  
    new 接口名(){
      实现接口中的方法
      。。
    }.new 内部类类名()具体你可以看下内部类的教程,google一下有很多。
      

  2.   

    接口中的类是public static 的,实例化似乎没有用。Interface interface1 {    class innerC {
            String str = "str";
            void f1(){
                 System.out.println("inner");
            }
        }
    }
      

  3.   

    接口中的类是抽象的  默认的是  public abstract 修饰  不能实现,怎么可以调用呢  
      

  4.   


    Interface interface1 {    class innerC {
            String str = "str";
            void f1(){
                 System.out.println("inner");
            }
        }
    }这个内部类怎么用?
      

  5.   


    public interface ClassInInterface {
      void howdy();
      class Test implements ClassInInterface{
    @Override
    public void howdy() {
    System.out.println("Howdy");
    }
     public static void main(String[] args) {
     new Test().howdy();
    }
      }
    }java编程思想中的一个例子。
      

  6.   

    匿名类如何
    new interface1(){}.innerC.f1();
      

  7.   

    class Test implement interface1 {public static void main(String str[])
    {innerc test=new innerc();
    test.f1();
    }}
      

  8.   

    难道是只在static中有用?加载的时候就调?
      

  9.   


    这么用,类名首字母最好大写。public static void main(String[] args) {
        interface1.innerC c = new interface1.innerC();
        c.f1();
    }