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[]) {
ShellMark_to_win s = new ShellMark_to_win();
s.test();
}
}
更多内容请见原文,文章转载自:https://blog.csdn.net/qq_44639795/article/details/103110007
最新文章
- ASP.NET Core管道深度剖析(2):创建一个&ldquo;迷你版&rdquo;的管道来模拟真实管道请求处理流程
- 【H5疑难杂症】脱离文档流时的渲染BUG
- 微信开放平台开发——网页微信扫码登录(OAuth2.0)
- mui,css3 querySelector,appendChild,style.display,insertBefore
- Divide and Conquer:River Hopscotch(POJ 3258)
- 深入理解java虚拟机(7)---线程安全 &; 锁优化
- [BZOJ3872][Poi2014]Ant colony
- java substring和substr
- Python新手学习基础之循环语句——While循环
- Trie树|字典树(字符串排序)
- Internet基础
- 逐步在Windows上结合CopSSH + msysGit安装安装Git Server同时集成Git使用Visual Studio
- mybatis_SQL缓存(5)
- APP-8.2-Postman应用
- Python MySQL - 进行数据查询
- 通过sql实现约束
- jenkins修改时区
- 你应该知道的PHP库
- mysql 创建,授权,删除 用户
- 《剑指offer》---字符串的全排列