Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

match the folowing type of exceptions What type of exceptions do the following p

ID: 3836158 • Letter: M

Question

match the folowing type of exceptions

What type of exceptions do the following programs throw? Each exception is used once. public class Test {public static void main (Siring [] args) {System.out.println {1/0);}} public class Test {public static void main (String[] args) {int[] list = rew int[5]; System.out.println (list [5]);}} public class Test {public static void main(String|| args) {String 5 - "abc"; System.out.println (s.charAt (3));}} public class Test {public static void main (String [] args) {Object o = new Object (); String d = (String)o;}} A. Class Cast Exception B. Null Pointer Exception C. String Index Out Of Bounds Exception D. Arithmetic Exception E. Array Index Out Of Bounds Exception F. No exception

Explanation / Answer

1. When you divide a number by zero, you will get ArithmeticException : Divided By zero Exception. Ans is D
2. When we try to access an element in the array that is out of bounds, we will get ArrayIndexOutOfBoundsException. Ans is E
3. When we try to access a character in the String that is out of bounds, we will get StringIndexOutOfBoundsException. Ans is C
4. When we try to cast the class to another class, which is unsupported, we will get ClassCastExceptin. Answer is A