Topic: 内嵌类(静态内部类) 如何在外部类外面创建实例? |
Print this page |
1.内嵌类(静态内部类) 如何在外部类外面创建实例? | Copy to clipboard |
Posted by: ronnin Posted on: 2004-09-21 21:35 如题 thanks forward |
2.Re:内嵌类(静态内部类) 如何在外部类外面创建实例? [Re: ronnin] | Copy to clipboard |
Posted by: littledeer1974 Posted on: 2004-09-22 09:47 应该不能吧,也许我没有理解你的意思 |
3.Re:内嵌类(静态内部类) 如何在外部类外面创建实例? [Re: ronnin] | Copy to clipboard |
Posted by: ronnin Posted on: 2004-09-22 10:29 class Outer{ static class Inner{ } } class Test{ Outer outer = new Outer(); // given a obj of Outer // here, how to instanlize a Inner } |
4.Re:内嵌类(静态内部类) 如何在外部类外面创建实例? [Re: ronnin] | Copy to clipboard |
Posted by: littledeer1974 Posted on: 2004-09-22 10:41 ronnin wrote:class Outer{ 静态的类都是在运行时静态的加载到内存中的(一开始运行首先从静态的类开始),所以也不需要对他们进行初始化(所以也没有实例,因此在类的内部也不能用this) 如果是静态内部类的话 1.静态内部类不能操作访问外部数据 2.静态内部类的实例生成不需要从外部生成相关类(包含内部类的 class Outer) 如果不是静态的类可以如下操作 class Outer{ (以上个人理解,仅供参考) |
5.Re:内嵌类(静态内部类) 如何在外部类外面创建实例? [Re: ronnin] | Copy to clipboard |
Posted by: ronnin Posted on: 2004-09-22 12:17 quote: _____静态的类都是在运行时静态的加载到内存中的(一开始运行首先从静态的类开始)? Q: ____这里是指静态外部类? 如: ________static class MyClass{} ____这样不可以吧? ____Error Message:" only pulic, abstract, final are permitted" ps: 行前的“_”代替空格 |
6.Re:内嵌类(静态内部类) 如何在外部类外面创建实例? [Re: ronnin] | Copy to clipboard |
Posted by: ronnin Posted on: 2004-09-22 12:38 class Outer{ ____class Inner{ ________public someMethod(){ //some code ________} ____} } class Test{ ____Outer outer = new Outer(); // given a obj of Outer ____// here, how to instanlize a Inner ____Outer.Inner youwant=new Outer.Inner(); // fail to compile ____// should be "Outer.Inner youwant = outer.new Inner(); " ____void someMtd(){ ________youwant.someMethod(); //if it is not static ____} } |
7.Re:内嵌类(静态内部类) 如何在外部类外面创建实例? [Re: ronnin] | Copy to clipboard |
Posted by: ronnin Posted on: 2004-09-22 12:43 I see if nested class(static inner class), Instanlized as follows: Outer.Inner youwant=new Outer.Inner(); thank you, littledeer1974 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |