Modern Programming Languages MCQs with Answers
Practice important Modern Programming Languages MCQs with answers and explanations.
Multiple Choice Questions
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
View Answer
C
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
View Answer
A
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
View Answer
B
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
View Answer
B
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
View Answer
A
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.
View Answer
B
Q567: In Java, which method is used to start a thread?
- A: start()
- B: sleep()
- C: yield()
- D: run()
View Answer
A
Q568: Which method is used to pause a thread for a specified time in Java?
- A: sleep()
- B: wait()
- C: notify()
- D: yield()
View Answer
A
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
View Answer
B
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
View Answer
C