a problem about anonymous inner!!

dennis_woo 2001-11-26 01:40:38
15. Which of the following statements are true?
A) An anonymous class cannot have any constructors
B) An anonymous class can only be created within the body of a method
C) An anonymous class can only access static fields of the enclosing class
D) An anonymous class instantiated and declared in the same place.

C)为什么不对?能否举个例子?
...全文
80 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
item 2001-11-28
  • 打赏
  • 举报
回复
give me fen!
dennis_woo 2001-11-26
  • 打赏
  • 举报
回复
说得都对,以下是我的测试结果以供大家参考:

new B(){ void abstractB(){
System.out.println(strStatic);//静态
System.out.println(unStatic);//非静态
System.out.println(_STR);//final
method1();//method of the enclosing class

};
};
spczhou 2001-11-26
  • 打赏
  • 举报
回复
f.addMouseMotionListener ( new MouseMotionAdapter() {
public void mouseDragged (MouseEvent e) {
String s = "Mouse dragging: X = " + e.getX() + " Y = " + e.getY();
tf.setText (s);
}
} );
注意tf,它可不是static
jsyx 2001-11-26
  • 打赏
  • 举报
回复
应该还可以访问final

62,614

社区成员

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

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