[求助]内部类能访问外部类的成员吗?

Steve_Samuelson 2008-04-26 09:41:02

class $2041_Window extends Frame{
$2041_Window(){
this.setBounds(50, 50, 300, 300);
this.setVisible(true);
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
setVisible(false);
//我在这个位置想访问$2041_Window的对象?
}
});
}
}
...全文
118 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
yaray 2008-04-26
  • 打赏
  • 举报
回复
多动手试试: 一试便知
我是风 2008-04-26
  • 打赏
  • 举报
回复
这样访问:
class $2041_Window extends Frame{
private int intValue = 10;
$2041_Window(){
this.setBounds(50, 50, 300, 300);
this.setVisible(true);
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
setVisible(false);
//我在这个位置想访问$2041_Window的对象?
System.out.println($2041_Window.this.intValue);
}
});
}
}
anqini 2008-04-26
  • 打赏
  • 举报
回复
可以啊,对内部类来说外部类的内容是可以访问的!但要注意静态和非静态!
老紫竹 2008-04-26
  • 打赏
  • 举报
回复
可以访问外部类的类一级成员,或者方法级的final 成员

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧