Question: Differentiate the three kinds of exceptionsRuntimeException, Exception, and Error. Explain the appropriate strategy to handle each kind. 4. What exception type does the following program

Differentiate the three kinds of exceptionsRuntimeException, Exception, and Error. Explain the appropriate strategy to handle each kind.

4. What exception type does the following program segments throw, if any? Explain the difference.

I.

public class Test {

public static void main(String[] args) {

Object o = null;

System.out.println(o.toString());

}

}

II.

public class Test {

public static void main(String[] args) {

Object o = null;

System.out.println(o);

}

}

5. What exception type does the following program throw and why?

public class Test {

public static void main(String[] args) {

Object o = new Object();

String d = (String)o;

}

}

A. ArithmeticException

B. ArrayIndexOutOfBoundsException

C. StringIndexOutOfBoundsException

D. ClassCastException

E. No exception

6. What exception type does the following program throw? Explain the difference.

I.

public class Test {

public static void main(String[] args) {

int[] list = new int[5];

System.out.println(list[5]);

}

}

II.

public class Test {

public static void main(String[] args) {

String s = "abc";

System.out.println(s.charAt(3));

}

}

7. In the LuckyNumber program in Fig 15.1 (p664), 1) what will happen if user enters 34 at the "Enter your lucky number (an integer):" prompt message? Explain. 2)what if user enters 3r4 at the "Enter your lucky number (an integer):" prompt message? Explain.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!