- class Outer
- {
-
- //如果局部内部类要想在任何位置去使用,我这个局部内部类应该当作返回值对象返回
- public English show(){
-
- class Inner implements English
- {
- public void run(){
- }
- public void speak(){
- System.out.println("说英语");
- }
- }
- return new Inner();
-
- }
-
- }
- interface English
- {
- void speak();
- }
- class Test
- {
- public static void main(String[] args){
- Outer o = new Outer();
- English e = o.show();
- e.speak();
- }
- }
复制代码 |
|