Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 内嵌类(静态内部类) 如何在外部类外面创建实例?
ronnin

偶又错了么?



发贴: 59
积分: 0
于 2004-09-21 21:35 user profilesend a private message to usersend email to ronninsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
如题

thanks forward



作者 Re:内嵌类(静态内部类) 如何在外部类外面创建实例? [Re:ronnin]
littledeer1974

Garbage Collector

CJSDN高级会员


发贴: 1517
积分: 122
于 2004-09-22 09:47 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
应该不能吧,也许我没有理解你的意思Black Eye


Surround yourself with people who are open to change

作者 Re:内嵌类(静态内部类) 如何在外部类外面创建实例? [Re:ronnin]
ronnin

偶又错了么?



发贴: 59
积分: 0
于 2004-09-22 10:29 user profilesend a private message to usersend email to ronninsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
class Outer{
static class Inner{

}
}

class Test{
Outer outer = new Outer(); // given a obj of Outer
// here, how to instanlize a Inner
}



作者 Re:内嵌类(静态内部类) 如何在外部类外面创建实例? [Re:ronnin]
littledeer1974

Garbage Collector

CJSDN高级会员


发贴: 1517
积分: 122
于 2004-09-22 10:41 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
ronnin wrote:
class Outer{
static class Inner{

}
}

class Test{
Outer outer = new Outer(); // given a obj of Outer
// here, how to instanlize a Inner
}


静态的类都是在运行时静态的加载到内存中的(一开始运行首先从静态的类开始),所以也不需要对他们进行初始化(所以也没有实例,因此在类的内部也不能用this)
如果是静态内部类的话
1.静态内部类不能操作访问外部数据
2.静态内部类的实例生成不需要从外部生成相关类(包含内部类的 class Outer)

如果不是静态的类可以如下操作

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();
youwant.someMethod();
//if it is not static

}

(以上个人理解,仅供参考)


littledeer1974 edited on 2004-09-22 11:06

Surround yourself with people who are open to change

作者 Re:内嵌类(静态内部类) 如何在外部类外面创建实例? [Re:ronnin]
ronnin

偶又错了么?



发贴: 59
积分: 0
于 2004-09-22 12:17 user profilesend a private message to usersend email to ronninsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
quote:
_____静态的类都是在运行时静态的加载到内存中的(一开始运行首先从静态的类开始)?

Q:
____这里是指静态外部类? 如:
________static class MyClass{}
____这样不可以吧?
____Error Message:" only pulic, abstract, final are permitted"

ps: 行前的“_”代替空格 Clown


ronnin edited on 2004-09-22 12:19

作者 Re:内嵌类(静态内部类) 如何在外部类外面创建实例? [Re:ronnin]
ronnin

偶又错了么?



发贴: 59
积分: 0
于 2004-09-22 12:38 user profilesend a private message to usersend email to ronninsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
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
____}
}
Clown


ronnin edited on 2004-09-22 12:54

作者 Re:内嵌类(静态内部类) 如何在外部类外面创建实例? [Re:ronnin]
ronnin

偶又错了么?



发贴: 59
积分: 0
于 2004-09-22 12:43 user profilesend a private message to usersend email to ronninsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
I see
if nested class(static inner class), Instanlized as follows:

Outer.Inner youwant=new Outer.Inner();

thank you, littledeer1974

Clown




flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   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