Thread Important Objective Questions - Part 1



1

Which is the correct way to start a new thread?

Select the one correct answer.

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

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

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

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

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

2    

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

Select the one correct answer.

    begin()

    start()

    run()

    resume()

    behavior()



Which statements are true?

Select the two correct answers.

    The class Thread is abstract.

    The class Thread implements Runnable.

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

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

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

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.

    The program will fail to compile.

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

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

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

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

No comments:

Post a Comment