java中内部类中还有内部类请给实例!
来源:互联网 发布:阿里云邮箱格式咋写 编辑:程序博客网 时间:2024/06/06 05:55
2.当内部类中还有一个内部类,下面给出了一个实例。【新手可忽略不影响继续学习】(以下多出代码, 用蓝色标记)
例2.2:
class ShellMark_to_win {
int shell_x = 100;//马克-to-win:既然每个内部类实例都可以改变这里的外层类静态属性或实例属性,这里成为内部类实例们可以交互的地方
static int n;
void visitCore() {
Core core = new Core();
core.y=8;
core.display();
}
// 下面是个实例内部类,必须有个外层类实例,才能有这个内部类实例。所以就有了this这个概念。
class Core {
// static int m=9;
int y = 10; // y is local to core
void display() {
shell_x=shell_x+20;
n=n+1;//轻松访问外层类的静态变量
System.out.println("n is "+n+" display: shell_x and y " + shell_x + " "+ShellMark_to_win.this.shell_x+ " " + y+ " "+this.y);
}
class CoreCore{
void displayDis() {
Core.this.display();
}
}
}
Core newC()
{
return new Core();
}
void showy() {
// y=9; // 错误,马克-to-win:外层类不能直接访问内部类的属性。error,y not known here! System.out.println(y);
}
}
public class Test {
public static void main(String args[]) {
ShellMark_to_win shell = new ShellMark_to_win();
shell.visitCore();
ShellMark_to_win.Core sc=shell.new Core();//马克-to-win:内部类是存在于外部对象里的。
。。。。。。。。。。。。。。。。。
详情请进:http://www.mark-to-win.com/JavaBeginner/JavaBeginner4_web.html#InnerInnerClass
例2.2:
class ShellMark_to_win {
int shell_x = 100;//马克-to-win:既然每个内部类实例都可以改变这里的外层类静态属性或实例属性,这里成为内部类实例们可以交互的地方
static int n;
void visitCore() {
Core core = new Core();
core.y=8;
core.display();
}
// 下面是个实例内部类,必须有个外层类实例,才能有这个内部类实例。所以就有了this这个概念。
class Core {
// static int m=9;
int y = 10; // y is local to core
void display() {
shell_x=shell_x+20;
n=n+1;//轻松访问外层类的静态变量
System.out.println("n is "+n+" display: shell_x and y " + shell_x + " "+ShellMark_to_win.this.shell_x+ " " + y+ " "+this.y);
}
class CoreCore{
void displayDis() {
Core.this.display();
}
}
}
Core newC()
{
return new Core();
}
void showy() {
// y=9; // 错误,马克-to-win:外层类不能直接访问内部类的属性。error,y not known here! System.out.println(y);
}
}
public class Test {
public static void main(String args[]) {
ShellMark_to_win shell = new ShellMark_to_win();
shell.visitCore();
ShellMark_to_win.Core sc=shell.new Core();//马克-to-win:内部类是存在于外部对象里的。
。。。。。。。。。。。。。。。。。
详情请进:http://www.mark-to-win.com/JavaBeginner/JavaBeginner4_web.html#InnerInnerClass
0 0
- java中内部类中还有内部类请给实例!
- java中内部类中还有内部类请给实例!
- java 中内部类
- java中内部类
- Java中内部类
- java中内部类
- java中内部类
- Java中内部类
- Java中内部类
- Java中内部类
- java中内部类
- java中内部类实例理解
- Java中内部类的实例化
- java中内部类实例练习
- java中内部类的实例化
- java中如何实例化内部类
- java中匿名内部类
- java中内部类笔记
- js/java 页面url传值中文编码&解码问题
- UltraEdit21.20.0.1001 查找功能 失灵 无法使用 修复方法
- 线性规划与网络流24题の18 分配问题(最小费用最大流、最大费用最大流)
- Paint方法setXfermode
- 【索引】Maintaining Interval Data
- java中内部类中还有内部类请给实例!
- jquery 全屏对话框
- 国际化
- 如何在Mac OS X上创建一个Service服务进程
- 求助
- 接口interface和private私有内部类怎样一块配合着用?
- 简单介绍龙芯汇编
- 【索引】Maintaining Interval Data :: Examples
- 好用的select美化