Review Questions

graphics/rq_icon.gif

9.1

Which is the correct way to start a new thread?

Select the one correct answer.

  1. Just create a new Thread object. The thread will start automatically.

  2. Create a new Thread object and call the method begin().

  3. Create a new Thread object and call the method start().

  4. Create a new Thread object and call the method run().

  5. Create a new Thread object and call the method resume().

9.2

When extending the Thread class to provide a thread's behavior, which method should be overridden?

Select the one correct answer.

  1. begin()

  2. start()

  3. run()

  4. resume()

  5. behavior()

9.3

Which statements are true?

Select the two correct answers.

  1. The class Thread is abstract.

  2. The class Thread implements Runnable.

  3. Classes implementing the Runnable interface must define a method named start.

  4. Calling the method run() on an object implementing Runnable will create a new thread.

  5. A program terminates when the last non-daemon thread ends.

9.4

What will be the result of attempting to compile and run the following program?

public class MyClass extends Thread {
    public MyClass(String s) { msg = s; }
    String msg;
    public void run() {
        System.out.println(msg);
    }

    public static void main(String[] args) {
        new MyClass("Hello");
        new MyClass("World");
    }
}

Select the one correct answer.

  1. The program will fail to compile.

  2. The program will compile without errors and will print Hello and World, in that order, every time the program is run.

  3. The program will compile without errors and will print a never-ending stream of Hello and World.

  4. The program will compile without errors and will print Hello and World when run, but the order is unpredictable.

  5. The program will compile without errors and will simply terminate without any output when run.



     
    ASPTreeView.com
     
    Evaluation has №РБПБХЧАЦexpired.
    Info...