SCJP題庫第232題

 
Given:
1. public class Threads5{
2.   public static void main(String[] args){
3.     new Thread(new Runnable(){
4.     public void run(){
5.       System.out.print("bar");
6.     }}).start();
7.   }
8. }
What is the result?
A. Compilation fails.
B. An exception is thrown at runtime.
C. The code executes normally and prints "bar".
D. The code executes normally, but nothing prints.

Ans: C

解說:第3行直接新增一個Thread物件並執行其物件方法start,並且在第4~6行加入run方法的實作,此題可以正常地執行,並印出bar字串。

Comments

Popular posts from this blog

Android-使用webview在V3版的Google地圖GPS定位