SCJP考试练习题2

6.True or False: Readers have methods that can read and return floats and doubles.

  A. Ture 
  B. False 
答案:B

分析:Reader/Writer只处理Unicode字符的输入输出。float和double可以通过stream进行I/O 

 

---------------------------------------------------------------------------------------

7.What does the following paint() method draw? 

  1. public void paint(Graphics g) { 
  2. g.drawString(“Any question”, 10, 0); 
  3. } 
  A. The string “Any question?”, with its top-left corner at 10,0 
  B. A little squiggle coming down from the top of the component. 

答案:B

分析:简评:drawString(String str, int x, int y)方法是使用当前的颜色和字符,将str的内容显示出来,并且最左的字符的基线从(x,y)开始。在本题中,y=0,所以基线位于最顶端。我们只能看到下行字母的一部分,即字母‘y’、‘q’的下半部分。 

 

-----------------------------------------------------------------------

8.What happens when you try to compile and run the following application? Choose all  correct options. 

 

  A. The application compiles but doesn't print anything. 
  B. The application compiles and print “DONE WAITING” 
  C. The application compiles and print “FINALLY” 
  D. The application compiles and print “ALL DONE” 
  E. The application compiles and print “INTERRUPTED” 

答案:A

分析:在Java中,每一个对象都有锁。任何时候,该锁都至多由一个线程控制。由于alias1与alias2指向同一对象test2,在执行alias2.wait();前,线程拥有对象test2的锁。在执行完alias2.wait();以后,该线程释放了对象test2的锁,进入等待池。但此后没有线程调用对象Z的notify()和notifyAll()方 法,所以该进程一直处于等待状态,没有输出。 

 

----------------------------------------------------------------------------------------

9.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). 
答案:ABE

分析:由于类是public,所以文件名必须与之对应,选项A正确。如果不在2、3行之间加上super(nrows,ncols)的话,则会调用无参数构建器TextArea(), 使nrows、ncols信息丢失,故选项B正确。在Java2中,所有的事件处理方法都不返回值,选项C、D错误。选项E正确,因为如果不加 super.processTextEvent(te),注册的listener将不会被唤醒。

 

------------------------------------------------------------------------------------------------------------

10.Which declarations of identifiers are legal? 
A. $persons 
B. TwoUsers 
C. *point 
D. this 
E. _endline 
答案:ABE

分析:Java的标识符可以以一个Unicode字符,下滑线(_),美元符($)开始,后续字符可以是前面的符号和数字,没有长度限制,大小写敏感,不能是保留字。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值