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[]) {
        ShellMark_to_win s = new ShellMark_to_win();
        s.test();
    }
}

更多内容请见原文,文章转载自:https://blog.csdn.net/qq_44639795/article/details/103110007

最新文章

  1. ASP.NET Core管道深度剖析(2):创建一个&ldquo;迷你版&rdquo;的管道来模拟真实管道请求处理流程
  2. 【H5疑难杂症】脱离文档流时的渲染BUG
  3. 微信开放平台开发——网页微信扫码登录(OAuth2.0)
  4. mui,css3 querySelector,appendChild,style.display,insertBefore
  5. Divide and Conquer:River Hopscotch(POJ 3258)
  6. 深入理解java虚拟机(7)---线程安全 &amp; 锁优化
  7. [BZOJ3872][Poi2014]Ant colony
  8. java substring和substr
  9. Python新手学习基础之循环语句——While循环
  10. Trie树|字典树(字符串排序)
  11. Internet基础
  12. 逐步在Windows上结合CopSSH + msysGit安装安装Git Server同时集成Git使用Visual Studio
  13. mybatis_SQL缓存(5)
  14. APP-8.2-Postman应用
  15. Python MySQL - 进行数据查询
  16. 通过sql实现约束
  17. jenkins修改时区
  18. 你应该知道的PHP库
  19. mysql 创建,授权,删除 用户
  20. 《剑指offer》---字符串的全排列

热门文章

  1. .NetCore Web Api 利用ActionFilterAttribute统一接口返回值格式
  2. Linux 磁盘inode字节数占满的问题
  3. 基于ECS搭建云上博客(云小宝码上送祝福,免费抽iphone13任务详解)
  4. 4月28日 python学习总结 线程与协程
  5. 后端跨域问题究极解决 nginx+springboot 解决OPTIONS通过却报CORS的问题
  6. ms17-010-永恒之蓝漏洞利用教程
  7. ubuntu忘记密码,用root修改Ubuntu密码
  8. JS如何通过月份,计算月份相差几个月
  9. 浅析DES原理
  10. 半吊子菜鸟学Web开发 -- PHP学习5-数据库