Java - 查看比较嵌套类和匿名内部类的示例

时间:2013-10-16 23:34:50

标签: java class nested anonymous

有人能为我提供一个常规嵌套类的简单示例,然后将同一个类重写为匿名内部类吗?

1 个答案:

答案 0 :(得分:1)

以下是示例:

 public class Outer {
     public static class NestedStatic implements Runnable {

         public void run(){
             doSomething();

         }
     public static void main(String[] args){
         Thread nestThread=new Thread(new NestedStatic());
         nestThread.start();

         // now anonymous:
         Thread anonThread=new Thread(new Runnable(){
             public void run(){
                 doSomethingElse();
             });
         anonThread.start(); 
     }
}