Modern Programming Languages MCQs with Answers
Practice important Modern Programming Languages MCQs with answers and explanations.
Chapter: 29
Q561:
In Java, how are exceptions handled?
A. Using the catch block only
B. Using the try block only
C. Using try, catch, and optionally finally
D. Using only throws statement
Correct Answer:
C
Chapter: 29
Q562:
What is the main function of the 'throw' keyword in Java?
A. It defines an exception handler
B. It defines a method signature
C. It throws an exception explicitly
D. It catches exceptions
Correct Answer:
A
Chapter: 29
Q563:
What type of exceptions must be handled or declared in Java methods?
A. Unchecked exceptions
B. Checked exceptions
C. IOException exceptions
D. All exceptions
Correct Answer:
B
Chapter: 29
Q564:
What is the result of a 'throw' statement in Java?
A. It terminates the method without executing further
B. It re-throws the exception in the same method
C. It handles the exception
D. It throws a new exception object
Correct Answer:
B
Chapter: 29
Q565:
What happens when an exception is thrown in the try block?
A. It skips the catch block
B. It executes the finally block only
C. It is caught by the first matching catch block
D. It terminates the program
Correct Answer:
A
Chapter: 30
Q566:
What is the purpose of the finally clause in Java exception handling?
A. It executes only when an exception occurs.
B. It ensures clean-up operations are performed after a try block.
C. It executes only when no exception occurs.
D. It prevents exceptions from being thrown.
Correct Answer:
B
Chapter: 30
Q567:
In Java, which method is used to start a thread?
A. start()
B. sleep()
C. yield()
D. run()
Correct Answer:
A
Chapter: 30
Q568:
Which method is used to pause a thread for a specified time in Java?
A. sleep()
B. wait()
C. notify()
D. yield()
Correct Answer:
A
Chapter: 30
Q569:
In the context of Java threads, what does the notify() method do?
A. Wakes up all waiting threads
B. Wakes up a single waiting thread
C. Pauses the thread for a specified time
D. Terminates the thread
Correct Answer:
B
Chapter: 30
Q570:
What is the correct way to create a thread in Java by subclassing?
A. By extending the Runnable interface
B. By implementing the Thread class
C. By extending the Thread class
D. By implementing the Executor interface
Correct Answer:
C
Chapter: 30
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.
Correct Answer:
D
Chapter: 30
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
Correct Answer:
B
Chapter: 30
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
Correct Answer:
B
Chapter: 30
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.
Correct Answer:
B
Chapter: 30
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.
Correct Answer:
B
Chapter: 30
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.
Correct Answer:
B
Chapter: 30
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.
Correct Answer:
A
Chapter: 30
Q578:
Which of the following methods is used for thread synchronization in Java?
A. notify()
B. join()
C. wait()
D. yield()
Correct Answer:
C
Chapter: 30
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.
Correct Answer:
B
Chapter: 30
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
Correct Answer:
C