
Final Quiz

Quiz
•
Computers
•
University
•
Hard
Pravat Jena
Used 2+ times
FREE Resource
20 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
class MyThread extends Thread {
public void run() {
System.out.println("Child Thread");
}
public static void main(String[] args) {
MyThread t = new MyThread();
t.start();
System.out.println("Main Thread");
}
}
Only "Child Thread"
Only "Main Thread"
"Main Thread" followed by "Child Thread"
Either "Child Thread" or "Main Thread" may come first
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What will be the output if run() is called instead of start()?
MyThread t = new MyThread();
t.run();
System.out.println("Main Thread");
"Child Thread" and "Main Thread" printed from different threads
"Child Thread" and "Main Thread" printed from the same thread
Only "Main Thread"
Compilation error
3.
MULTIPLE CHOICE QUESTION
20 sec • 1 pt
What is the state of a thread once the start() method is called but before run() is executed?
New
Runnable
Running
Blocked
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
public class Test extends Thread {
public void run() {
System.out.println("Running");
}
public static void main(String[] args) {
Test t1 = new Test();
Test t2 = new Test();
t1.start();
t2.start();
}
}
How many threads are running?
1
2
3
4
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
public class SyncTest {
public synchronized void test() {
System.out.println(Thread.currentThread().getName() + " is running");
}
public static void main(String[] args) {
SyncTest obj = new SyncTest();
Thread t1 = new Thread(() -> obj.test());
Thread t2 = new Thread(() -> obj.test());
t1.start();
t2.start();
}
}
Both threads run together
Only one thread runs
Threads run one after another due to synchronization
Compilation error
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
public class MyClass {
public synchronized void methodA() {
System.out.println("Method A - " + Thread.currentThread().getName());
}
public void methodB() {
synchronized (this) {
System.out.println("Method B - " + Thread.currentThread().getName());
}
}
}
If two threads call methodA() and methodB() on the same object, which statement is true?
Both can execute simultaneously
Only one can execute at a time
They may deadlock
It causes a compilation error
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
public class Counter {
private int count = 0;
public synchronized void increment() {
count++;
}
public int getCount() {
return count;
}
}
Two threads each call increment() 1000 times. What can be said about getCount()?
Will cause an exception
B. Always less than 2000
Could be 2000 or less
Always 2000
Create a free account and access millions of resources
Similar Resources on Wayground
20 questions
2-mavzu. Kotlin dasturlash tilida tarmoqlanuvchi, takrorlanuvchi

Quiz
•
University
18 questions
Java thread - MCQ

Quiz
•
University
20 questions
Java Quiz 1

Quiz
•
University
20 questions
Sumatif Arduino

Quiz
•
12th Grade - University
15 questions
Quiz Pemrograman Berorientasi Obyek

Quiz
•
University
20 questions
Fianal JAVA OOP

Quiz
•
University
15 questions
Array Java

Quiz
•
University
25 questions
DSA - Q1

Quiz
•
University
Popular Resources on Wayground
10 questions
Lab Safety Procedures and Guidelines

Interactive video
•
6th - 10th Grade
10 questions
Nouns, nouns, nouns

Quiz
•
3rd Grade
10 questions
9/11 Experience and Reflections

Interactive video
•
10th - 12th Grade
25 questions
Multiplication Facts

Quiz
•
5th Grade
11 questions
All about me

Quiz
•
Professional Development
22 questions
Adding Integers

Quiz
•
6th Grade
15 questions
Subtracting Integers

Quiz
•
7th Grade
9 questions
Tips & Tricks

Lesson
•
6th - 8th Grade
Discover more resources for Computers
21 questions
Spanish-Speaking Countries

Quiz
•
6th Grade - University
20 questions
Levels of Measurements

Quiz
•
11th Grade - University
7 questions
Common and Proper Nouns

Interactive video
•
4th Grade - University
12 questions
Los numeros en español.

Lesson
•
6th Grade - University
7 questions
PC: Unit 1 Quiz Review

Quiz
•
11th Grade - University
7 questions
Supporting the Main Idea –Informational

Interactive video
•
4th Grade - University
12 questions
Hurricane or Tornado

Quiz
•
3rd Grade - University
7 questions
Enzymes (Updated)

Interactive video
•
11th Grade - University