java中什么是局部内部类Local inner class?

5.局部内部类Local inner class  (视频下载) (全部书籍)

马克-to-win:什么叫局部内部类?内部类声明位置:1.它的外部类的范围之内。2.在几个程序块的范围之内。例如,由方法定义的块中或甚至在for循环体内部。局部内部类有什么意义?意义就是:你希望这个类只被解决某个问题用,任何其他人,其他地方都不能用它。就像临时变量一样。马克-to-win:生活中百年不遇我们去海边玩,专门裁出一块布来铺在沙滩上, 但这块布干什么别的事都不合适,就属于这种情况。 

例2.5---本章源码

class ShellMark_to_win {
    int x = 100;
    void test() {
        for (int i = 0; i < 2; i++) {
/*马克-to-win:for循环之外,Core类不存在。 outside of this for loop, inner can not be used. */
            class Core {
                void display() {
                    System.out.println("外部类的x=" + x);
                }
            }
            Core inner = new Core();
            inner.display();
        }
    //    Core inner = new Core(); //错误找不到Core。
    }
}
public class Test {
    public static void main(String args[]) {
。。。。。。。。。。。。。。。。。
详情请进:http://www.mark-to-win.com/index.html?content=JavaBeginner/javaUrl.html&chapter=JavaBeginner/JavaBeginner4_web.html#LocalInnerClass

猜你喜欢

转载自www.cnblogs.com/mark-to-win/p/9694684.html