例题10: Which statement or statements are true about the code listed below? Choose three. 1. public class MyTextArea extends TextArea { 2. public MyTextArea(int nrows, int ncols) { 3. enableEvents(AWTEvent. TEXT_ EVENT_MASK); 4. } 5. 6. public void processTextEvent (TextEvent te) { 7. System.out.println(“Processing a text event.”); 8. } 9. } 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 new component will have the correct size. C. At line 6, the return type of processTextEvent() should be declared boolean, not void. D. Between lines 7 and 8, the following code should appear: return true. E. Between lines 7 and 8, the following code should appear: super.processTextEvent(te). 解答:A, B, E 点评:由于类是public,所以文件名必须与之对应,选项A正确。如果不在2、3行之间加上super(nrows,ncols)的话,则会调用无参数构建器TextArea(), 使nrows、ncols信息丢失,故选项B正确。在Java2中,所有的事件处理方法都不返回值,选项C、D错误。选项E正确,因为如果不加super.processTextEvent(te),注册的listener将不会被唤醒。 |