Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases In Action

Authors: Dave Bechberger, Josh Perryman

1st Edition

1617296376, 978-1617296376

More Books

Students also viewed these Databases questions

Question

6 What is the selection phase?

Answered: 1 week ago