会计考友 发表于 2012-8-4 12:33:16

2011年JAVA认证模拟题第二阶段(8)

  Q22.Assume the the class AcLis implements the ActionListener interface. The code fragment below constructs a button ande 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.
  Q23.Which statement or statements are true about the code listed below?
  1. public class MyTextArea extends TextArea {
  2. public MyTextArea(int nrows, int ncols) {
  3. enableEvents(AWTEvent.TEXT_EVENT_MASK);
  4. }
  5. public void processTextEvent(TextEvent te) {

  6. System.out.println(“Processing a text event”);

会计考友 发表于 2012-8-4 12:33:17

2011年JAVA认证模拟题第二阶段(8)

</p>  7. }
  8. }
  a. The source code must appear in a file called MyTextArea.java.
  b. Between lines 2 and 3, a call should be made to super(nrows,ncols) so that the next component will have the correct size.
  c. Between lines 6 and 7, the following code should appear “return true;”
  d. Between lines 6 and 7, the following code should appear “super.processTextEvent(te);”
  Q24.Which statement or statements are true about the code fragment listed below? (HINT The ActionListener and ItemListener interface each define a single method.)
  1. class MyListener implements ActionListener, ItemListener {
  2. public void actionPerformed(ActionEvent e) {
  3. System.out.println(“Action.”);
  4. }
  5. public void itemStateChanged(ItemEvent ie) {
  6. System.out.println(“Item.”);
  7. }
  8. }
  a. The code compiles without error.
  b. The code generates a compiler error at line 1.
  c. The code generates a compiler error at line 2.
  d. The code generates a compiler error at line 5.
  22. d
  23. abd
  24. a
页: [1]
查看完整版本: 2011年JAVA认证模拟题第二阶段(8)