当前位置: 技术问答>java相关
一道scjp的题目?立即结帐!!!!!
来源: 互联网 发布时间:2015-06-22
本文导语: 题目如下: Assume the class AcLis implements the ActionListener interface. The code fragment below constructs a button and gives it four action listeners. When the button is pressed, which action listener is the first to get its actionPerform...
题目如下:
Assume the class AcLis implements the ActionListener interface. The code fragment below constructs a button and gives it four
action listeners. When the button is pressed, which action listener is the first to get its actionPerformed() method invoked?
1. Button btn = new Button("Hello");
2. AcLis a1 = new AcLis();
3. AcLis a2 = new AcLis();
4. AcLis a3 = new AcLis();
5. btn.addActionListener(a1);
6. btn.addActionListener(a2);
7. btn.addActionListener(a3);
8. btn.removeActionListener(a2);
9. btn.removeActionListener(a3);
10. btn.addActionListener(a3);
11. btn.addActionListener(a2);
答案(单选)
a: a1 gets its actionPerformed() method invoked first.
b: a2 gets its actionPerformed() method invoked first.
c: a3 gets its actionPerformed() method invoked first.
d: It is impossible to know which listener will be first.
Assume the class AcLis implements the ActionListener interface. The code fragment below constructs a button and gives it four
action listeners. When the button is pressed, which action listener is the first to get its actionPerformed() method invoked?
1. Button btn = new Button("Hello");
2. AcLis a1 = new AcLis();
3. AcLis a2 = new AcLis();
4. AcLis a3 = new AcLis();
5. btn.addActionListener(a1);
6. btn.addActionListener(a2);
7. btn.addActionListener(a3);
8. btn.removeActionListener(a2);
9. btn.removeActionListener(a3);
10. btn.addActionListener(a3);
11. btn.addActionListener(a2);
答案(单选)
a: a1 gets its actionPerformed() method invoked first.
b: a2 gets its actionPerformed() method invoked first.
c: a3 gets its actionPerformed() method invoked first.
d: It is impossible to know which listener will be first.
|
应该是d
类似多线程问题,多个相同的listenser同时加载时,当响应click时,如同在线程池中唤醒某个处于waiting状态的线程,不能确定哪个被最先执行.
类似多线程问题,多个相同的listenser同时加载时,当响应click时,如同在线程池中唤醒某个处于waiting状态的线程,不能确定哪个被最先执行.
|
选择d,无法确定。你可以写一段代码试试,给予监听器不同的动作,多次执行,一定不同的结果。