
Multithreading
Quiz
•
Computers
•
University
•
Practice Problem
•
Hard
SUBHASH AGRAWAL
Used 4+ times
FREE Resource
Enhance your content in a minute
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

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?
Similar Resources on Wayground
10 questions
Java Quiz 1
Quiz
•
University
10 questions
Quiz ECIH Week 4
Quiz
•
University
10 questions
GSI DP-100 Day 1
Quiz
•
University - Professi...
10 questions
Java Arrays
Quiz
•
University
10 questions
Cybersecurity Fundamentals Week 6 Quiz
Quiz
•
KG - University
10 questions
Programacion Orientada a Objetos
Quiz
•
12th Grade - University
10 questions
OPPO Jan Virtual
Quiz
•
University
10 questions
Data Visualization Quiz
Quiz
•
University
Popular Resources on Wayground
8 questions
2 Step Word Problems
Quiz
•
KG - University
20 questions
Comparing Fractions
Quiz
•
4th Grade
15 questions
Fractions on a Number Line
Quiz
•
3rd Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
10 questions
Latin Bases claus(clois,clos, clud, clus) and ped
Quiz
•
6th - 8th Grade
22 questions
fractions
Quiz
•
3rd Grade
7 questions
The Story of Books
Quiz
•
6th - 8th Grade
Discover more resources for Computers
8 questions
2 Step Word Problems
Quiz
•
KG - University
7 questions
Comparing Fractions
Interactive video
•
1st Grade - University
7 questions
Force and Motion
Interactive video
•
4th Grade - University
10 questions
14.2 Independent/Dependent Variables
Quiz
•
KG - University
18 questions
Great Lakes States
Quiz
•
KG - University
7 questions
DNA, Chromosomes, Genes, and Traits: An Intro to Heredity
Interactive video
•
11th Grade - University
7 questions
Reflexive Verbs in Spanish
Lesson
•
9th Grade - University
7 questions
Narrative Writing 1
Interactive video
•
4th Grade - University
