Multithreading

Multithreading

University

8 Qs

quiz-placeholder

Similar activities

Quiz Pem Mobile

Quiz Pem Mobile

University

10 Qs

GODOT ENGINE

GODOT ENGINE

University

10 Qs

Quiz on Cyber Security

Quiz on Cyber Security

University

10 Qs

OOP Module 3 Tutorial (Quiz)

OOP Module 3 Tutorial (Quiz)

University

10 Qs

Quiz CodeIgniter 4

Quiz CodeIgniter 4

University

10 Qs

Quiz on Basics of C

Quiz on Basics of C

University

10 Qs

Cybersecurity

Cybersecurity

University

12 Qs

Cloud Computing Quiz

Cloud Computing Quiz

University

10 Qs

Multithreading

Multithreading

Assessment

Quiz

Computers

University

Practice Problem

Hard

Created by

SUBHASH AGRAWAL

Used 4+ times

FREE Resource

AI

Enhance your content in a minute

Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...

8 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

class MyThread implements Runnable {

public void run() {

System.out.println(Thread.currentThread().getName());

}

}

public class ThreadTest {

public static void main(String arg[]) {

Thread thread = new Thread(new MyThread());

thread.run();

thread.run();

thread.start();

}

}

main

main

Thread-0

Thread-0

main

Thread-1

main

Thread-0

Thread-1

Thread-0

Thread-1

Thread-2

2.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

class MyThread extends Thread {


public MyThread(String name) {

this.setName(name);

}


public void run() {

try {

sleep(100);

} catch (InterruptedException e) {

e.printStackTrace();

}

play();

}


private void play() {

System.out.print(getName());

System.out.print(getName());

}

}


public class ThreadTest {

public static void main(String args[]) throws InterruptedException {

Thread tableThread = new MyThread("Table");

Thread tennisThread = new MyThread("Tennis");

tableThread.start();

tennisThread.start();

}

}

a) This program will throw an IllegalStateException.

b) This program will always print the following: Tennis Tennis Table Table.

c) This program will always print the following: Table Table Tennis Tennis.

d) The output of this program cannot be predicted; it depends on thread scheduling.

3.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

class Worker extends Thread {

public void run() {

System.out.println(Thread.currentThread().getName());

}

}


public class Master {

public static void main(String[] args) throws InterruptedException {

Thread.currentThread().setName("Master ");

Thread worker = new Worker();

worker.setName("Worker ");

worker.start();

Thread.currentThread().join();

System.out.println(Thread.currentThread().getName());

}

}

a) When executed, the program prints the following: “Worker Master ”.

b) When executed, the program prints “Worker ”, and after that the program hangs (i.e., does not terminate).

c) When executed, the program prints “Worker ” and then terminates.

d) When executed, the program throws IllegalMonitorStateException.

e) The program does not compile and fails with multiple compiler errors.

4.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

What code is missing?

public class MyRunnable implements Runnable

{

public void run()

{

// some code here

}

}

new Thread(MyRunnable).run();

new Runnable(MyRunnable).start();

new Thread(new MyRunnable()).start();

new MyRunnable().start();

5.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

Which of the following line of code is suitable to start a thread?

class Demo implements Runnable

{

public void run() {

System.out.println(“Thread is in Running state”);

}


public static void main(String args[])

{

/* Missing code? */

}

}

Demo obj = new Demo();

Thread tobj = new Thread(obj);

tobj.start();

Thread t = new Thread(X);

t.start();

Thread t = new Thread(Demo);

Thread t = new Thread();

Demo.run();

6.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

class ThreadDemo extends Thread

{

public static void main(String [] args)

{

ThreadDemo t = new ThreadDemo();

t.start();

System.out.print("one. ");

t.start();

System.out.print("two. ");

}

public void run()

{

System.out.print("Thread ");

}

}

An exception occurs at runtime.

Compilation fails.

. It prints "Thread one. Thread two.".

The output cannot be determined.

7.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

1. public class Test extends Thread{

2. public static void main(String argv[]){

3. Test t = new Test();

4. t.run();

5. t.start();

6. }

7. public void run(){

8. System.out.println("run-test");

9. }

10. }

A. run-test run-test

B. run-test

C. Compilation fails due to an error on line 4

D. Compilation fails due to an error on line 7

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?