java进阶复习题
Name:_______________________
Covers Chs 29-31Sample Exam
Multiple Choice Questions Only for This Test
Part I: Questions: (1 pts each)
1 You should always invoke the unlock method in the finally clause.
A. true
B. false
2 Given the following code, which set of code can be used to replace the comment so that the program displays time to the console every second
import java.applet.*;
import java.util.*;
public class Test extends Applet implements Runnable {
public void init() {
Thread t = new Thread(this);
t.start();
}
public void run() {
for(; 😉 {
//display time every second
System.out.println(new Date().toString());
}
}
}
A. try { Thread.sleep(1000); } catch(InterruptedException e) { }
B. try { sleep(1000); } catch(InterruptedException e) { }
C. try { Thread.sleep(1000); } catch(RuntimeException e) { }
D. try { t.sleep(1000); } catch(InterruptedException e) { }
3 Which of the following expressions must be true if you create a thread using Thread = new Thread(object)
A. object instanceof Applet
B. object instanceof Thread
C. object instanceof Frame
D. object instanceof Runnable
4 How do you create a condition on a lock
A. Condition condition = Lock.getCondition();
B. Condition condition = Lock.newCondition();
C. Condition condition = lock.getCondition();
D. Condition condition = lock.newCondition();
5 Which method on a condition should you invoke to causes the current thread to wait until the condition is signaled
A. condition.waited();
B. condition.await();
C. condition.waiting();
D. condition.wait();
6 To run an object on a separate thread, the object must be a subclass of Thread.
A. true
B. false
7 The Runnable interface is more general than the Thread class. You can convert any class that extends Thread to a class that implements Runnable.
A. true
B. false
8 An exception occurs if the resume() method is invoked by a finished thread object.
A. true
B. false
9 You can set a priorit