Java From Beginner To Advanced

0% completed

Previous
Next
Quiz
Question 1
Which of the following is a checked exception in Java?
A
NullPointerException
B
IOException
C
ArithmeticException
D
ArrayIndexOutOfBoundsException
Question 2
Which keyword is used to handle exceptions in Java?
A
catch
B
throw
C
throws
D
try
Question 3
What does the throw keyword do in Java?
A
Catches an exception
B
Throws an exception
C
Declares an exception in a method signature
D
Prevents an exception from being thrown
Question 4
What is the output of the following Java code?
public class Solution {
    public static void main(String[] args) {
        try {
            int[] arr = new int[3];
            arr[5] = 10;
        } catch (ArrayIndexOutOfBoundsException e) {
            System.out.println("Array index out of bounds!");
        } finally {
            System.out.println("Finally block executed.");
        }
    }
}
A
Array index out of bounds! Finally block executed.
B
Finally block executed. Array index out of bounds!
C
Array index out of bounds!
D
Finally block executed.

.....

.....

.....

Like the course? Get enrolled and start learning!
Previous
Next