Web Design and Development MCQs with Answers
Practice important Web Design and Development MCQs with answers and explanations.
Chapter: 23
Q361:
What happens if you call start() on a thread that has already started?
A. It restarts the thread
B. It throws an exception
C. It does nothing
D. It stops the thread
Correct Answer:
B
Chapter: 23
Q362:
What is the primary difference between using Runnable interface and Thread class for multithreading?
A. Runnable requires thread creation, Thread does not
B. Thread class can be extended, Runnable cannot
C. Runnable requires extending a class, Thread does not
D. Both achieve the same result with different approaches
Correct Answer:
D
Chapter: 23
Q363:
In the PriorityEx.java example, what priority is assigned to the 'first' thread?
A. MAX_PRIORITY
B. MIN_PRIORITY
C. NORM_PRIORITY
D. 5
Correct Answer:
B
Chapter: 23
Q364:
Which class provides methods to manage thread priorities in Java?
A. Thread
B. Runnable
C. ExecutorService
D. Scheduler
Correct Answer:
A
Chapter: 23
Q365:
What issue may arise from using thread priorities in Java?
A. Priority mapping differences between JVM and OS
B. Increased CPU usage
C. Faster thread execution
D. Enhanced memory management
Correct Answer:
A
Chapter: 23
Q366:
What is the output of the ThreeLoopTest program with sequential execution?
A. All loops run simultaneously
B. Loops run one after another
C. Loops run in reverse order
D. Loops run in random order
Correct Answer:
B
Chapter: 23
Q367:
What keyword is used in Java to prevent a field from being serialized?
A. static
B. final
C. transient
D. volatile
Correct Answer:
C
Chapter: 23
Q368:
In the ThreadTest.java example using inheritance, what is the role of the Worker class?
A. It manages thread priorities
B. It provides the thread execution code
C. It initializes the thread scheduler
D. It handles thread synchronization
Correct Answer:
B
Chapter: 23
Q369:
What exception is thrown if an invalid priority is set for a thread?
A. IllegalArgumentException
B. IllegalThreadStateException
C. NullPointerException
D. ArrayIndexOutOfBoundsException
Correct Answer:
A
Chapter: 24
Q370:
Which method should be called to execute code in a thread?
A. run()
B. start()
C. execute()
D. runThread()
Correct Answer:
B
Chapter: 24
Q371:
What output difference is observed between sequential and multithreaded execution?
A. Sequential output is mixed
B. Multithreaded output is intermingled
C. Sequential output is faster
D. Multithreaded output is more stable
Correct Answer:
B
Chapter: 24
Q372:
How many threads are used in the example with inheritance approach to execute the ThreeLoopTest program?
A. One
B. Two
C. Three
D. Four
Correct Answer:
C
Chapter: 24
Q373:
What is the purpose of the Runnable interface in Java?
A. To execute code in parallel
B. To read data from files
C. To write data to files
D. To delay execution
Correct Answer:
A
Chapter: 24
Q374:
Which method in the ReadFile class handles file reading?
A. run()
B. start()
C. read()
D. execute()
Correct Answer:
A
Chapter: 24
Q375:
What is the output of running the Test class?
A. First file content followed by second file content
B. Second file content followed by first file content
C. Only the first file content
D. Only the second file content
Correct Answer:
A
Chapter: 24
Q376:
What does the sleep(int time) method do in Java?
A. Causes the thread to wait for a specified time
B. Causes the thread to exit
C. Immediately executes the thread
D. Increases the thread’s priority
Correct Answer:
A
Chapter: 24
Q377:
In which state is a thread when it has just been created but not yet started?
A. New state
B. Ready state
C. Running state
D. Dead state
Correct Answer:
A
Chapter: 24
Q378:
How does the yield() method affect thread execution?
A. It allows other threads of the same priority to execute
B. It terminates the thread
C. It makes the thread sleep for a specific time
D. It increases the thread's priority
Correct Answer:
A
Chapter: 24
Q379:
You can ---------to a network using sockets.
A. Read
B. Write
C. Read/Write
D. None of these
Correct Answer:
C
Chapter: 24
Q380:
Socket is a --------------communication channel between hosts.
A. Uni-directional
B. Bi-directional
C. Multi-directional
D. None of these
Correct Answer:
B