Modern Programming Languages MCQs with Answers
Practice important Modern Programming Languages MCQs with answers and explanations.
Multiple Choice Questions
Q571: Which of the following statements about Java threads is true?
- A: A thread has its own memory space.
- B: A thread can only run after the main program terminates.
- C: A thread can execute multiple programs at the same time.
- D: A thread shares memory space with other threads in the same process.
View Answer
D
Q572: What is the primary difference between notify() and notifyAll() in Java?
- A: notify() wakes up all threads, notifyAll() wakes up one thread
- B: notify() wakes up a single thread, notifyAll() wakes up all threads
- C: notify() pauses the thread, notifyAll() starts it
- D: notify() checks for thread safety, notifyAll() does not
View Answer
B
Q573: What does the run() method do when implementing the Runnable interface in Java?
- A: It creates a new thread
- B: It defines the code to be executed by the thread
- C: It starts the thread
- D: It pauses the thread
View Answer
B
Q574: What happens if a finally block contains a return statement in Java?
- A: The return statement in finally is ignored.
- B: The return statement in finally overrides the one in the try or catch block.
- C: The finally block will not execute.
- D: The catch block takes precedence.
View Answer
B
Q575: Which statement is true regarding Java Applets?
- A: Java Applets are standalone applications that do not require a browser.
- B: Java Applets run within a Java-enabled Web browser.
- C: Java Applets cannot be executed in a browser.
- D: Java Applets are a type of Java thread.
View Answer
B
Q576: What is the role of the run() method in a Java thread?
- A: It terminates the thread after execution.
- B: It contains the code to be executed by the thread.
- C: It sets the priority of the thread.
- D: It waits for the thread to finish execution.
View Answer
B
Q577: What type of control flow does the finally clause provide in Java exception handling?
- A: It provides a way to ensure that specific code executes regardless of an exception.
- B: It only executes when an exception is thrown.
- C: It prevents exceptions from being thrown.
- D: It pauses the execution until the catch block finishes.
View Answer
A
Q578: Which of the following methods is used for thread synchronization in Java?
- A: notify()
- B: join()
- C: wait()
- D: yield()
View Answer
C
Q579: In Java, which statement about the use of threads is correct?
- A: Threads are independent and do not share any resources.
- B: Threads share resources like memory but have their own stack.
- C: Threads have separate stacks and do not share memory space.
- D: Threads cannot be paused or stopped once started.
View Answer
B
Q580: What does the wait() method do in Java?
- A: Pauses the thread for a specified time
- B: Wakes up a thread that is waiting
- C: Prevents the thread from executing until notified
- D: Transfers control to another thread
View Answer
C