2011年1月26日 星期三

java inner class type

inner class type
1. anonymous class:
          * no class name, can be instantiated only once
  if (cancelTask != null) {
            new Thread() {
                public void run() {
                    try {
                        cancelTask.start();
                    } catch (Exception e) {
                        e.printStackTrace();
                        Log.e(TAG, e.toString());
                    }
                }
            }.start();

2. local class:
        * don't allow to be declared public, protected, private, static
        * valid area : within the code block
  //some code block
....... {
    class localclass {
    }
    localclass obj1 = new localclass();
    localclass obj2 = new localclass();
}

3. member class
       * define within the body of class
       * can be declared static ==> became as nested top-level class
       * valid area: within the body of outer class ==> static modifier break the rule

4. nested top-level class
        * used as a convenient way to group related classes without creating a new package

沒有留言:

張貼留言