Java Thread Basics and Lifecycle

Last Updated :
Discuss
Comments

Question 1

Which of the following is the correct way to create a thread in Java?

  • A

    Extending the Thread class

  • B

    Implementing the Runnable interface

  • C

    Both A and B

  • D

    Using the Callable interface only

Question 2

What will be the output of the following code?

Java
class MyThread extends Thread {
    public void run() {
        System.out.println("Thread is running");
    }

    public static void main(String[] args) {
        MyThread t = new MyThread();
        t.run();
    }
}


  • A

    Thread is running

  • B

    Compilation Error

  • C

    No Output

  • D

    Runtime Exception

Question 3

Which method is used to start a thread in Java?

  • A

    run()

  • B

    start()

  • C

    execute()

  • D

    begin()

Question 4

What is the initial state of a thread when it is created but not yet started?

  • A

    NEW

  • B

    RUNNABLE

  • C

    BLOCKED

  • D

    WAITING

Question 5

Which of the following statements about the Runnable interface is true?

  • A

    It contains the start() method

  • B

    It contains the run() method

  • C

    It can only be implemented by a class that extends Thread

  • D

    It cannot be used for multithreading

Question 6

What happens if start() is called twice on the same thread?

Java
class MyThread extends Thread {
    public void run() {
        System.out.println("Running...");
    }
    
    public static void main(String[] args) {
        MyThread t = new MyThread();
        t.start();
        t.start();
    }
}


  • A

    Thread runs twice

  • B

    Compiles and runs normally

  • C

    Throws IllegalThreadStateException

  • D

    No output

Question 7

Which of the following is NOT a valid thread state in Java?

  • A

    NEW

  • B

    TERMINATED

  • C

    RUNNING

  • D

    TIMED_WAITING

Question 8

What happens if sleep(1000) is called inside a thread?


  • A

    Thread execution is paused for 1 second

  • B

    Thread is terminated

  • C

    Thread goes to NEW state

  • D

    Thread execution continues immediately

Question 9

What will be the output of the following code?

Java
class Geeks {
    public static void main(String[] args) {
        Thread t = new Thread(() -> System.out.println("Hello from Thread"));
        t.start();
    }
}


  • A

    Hello from Thread

  • B

    Compilation Error

  • C

    No Output

  • D

    Runtime Exception

Question 10

Which method is used to wait for a thread to finish execution?


  • A

    wait()

  • B

    sleep()

  • C

    join()

  • D

    yield()

There are 10 questions to complete.

Take a part in the ongoing discussion