We have created a hierarchy of exceptions like below: A) The code written below throws an exception from the above hierarchy, depending on the value of c. Fill in the 5 gaps below, so that a correct working program is created. B) the following code throws two exceptions: Exception and ExceptionD. The exception name in the catch statement was removed as I expect you to recognize the order by which the exceptions are written in this code. B-1) what will be printed if the method is called by x = 0. B-2) what will be printed if the method is called by x = -1. B-3) what will be printed if the method is called by x = 1. C) A class called Exam is defined as below. Another class called TT2 extends class Exam and overrides all the three methods of Exam class. Specify what type of exceptions can be thrown by the methods that are defined in class TT2.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

We have created a hierarchy of exceptions like below: 

 

A) The code written below throws an exception from the above hierarchy, depending on the value of c.  

Fill in the 5 gaps below, so that a correct working program is created. 

 

 

B) the following code throws two exceptions: Exception and ExceptionD.  The exception name in the catch statement was removed as I expect you to recognize the order by which the exceptions are written in this code. 

 

 

B-1) what will be printed if the method is called by x = 0. 

 

B-2) what will be printed if the method is called by x = -1. 

 

B-3) what will be printed if the method is called by x = 1. 

 

 

C) A class called Exam is defined as below. 

 

Another class called TT2 extends class Exam and overrides all the three methods of Exam class. Specify what type of exceptions can be thrown by the methods that are defined in class TT2.  

B) the following code throws two exceptions: Exception and ExceptionD. The exception name in the catch statement was removed as I expect you to recognize the order by which the exceptions are written in this code.
public void fooMethod2(int x) {
try {
if (x == 0) throw new Exception();
else if (x < 0 ) throw new ExceptionD();
X = 10;
}
catch (
X = x + 1;
System.exit(0);
}
catch (
X = x + 100;
}
finally{
X = X + 2;
}
X = x + 3;
e) {
e ) {
System.out.println(x);
}
B-1) what will be printed if the method is called by x = 0.
B-2) what will be printed if the method is called by x = -1.
B-3) what will be printed if the method is called by x = 1.
C) A class called Exam is defined as below.
class Exam{
public void generateQuestion_1() throws Exceptionc {
// code was removed
}
public void generateQuestion_2() throws ExceptionD {
// code was removed
}
public void generateQuestion_3() throws Exception {
// code was removed
}
}
Another class called TT2 extends class Exam and overrides all the three methods of Exam class. Specify what type of exceptions can be thrown by the methods that are defined in class TT2.
Transcribed Image Text:B) the following code throws two exceptions: Exception and ExceptionD. The exception name in the catch statement was removed as I expect you to recognize the order by which the exceptions are written in this code. public void fooMethod2(int x) { try { if (x == 0) throw new Exception(); else if (x < 0 ) throw new ExceptionD(); X = 10; } catch ( X = x + 1; System.exit(0); } catch ( X = x + 100; } finally{ X = X + 2; } X = x + 3; e) { e ) { System.out.println(x); } B-1) what will be printed if the method is called by x = 0. B-2) what will be printed if the method is called by x = -1. B-3) what will be printed if the method is called by x = 1. C) A class called Exam is defined as below. class Exam{ public void generateQuestion_1() throws Exceptionc { // code was removed } public void generateQuestion_2() throws ExceptionD { // code was removed } public void generateQuestion_3() throws Exception { // code was removed } } Another class called TT2 extends class Exam and overrides all the three methods of Exam class. Specify what type of exceptions can be thrown by the methods that are defined in class TT2.
We have created a hierarchy of exceptions like below:
class ExceptionA extends Exception{
// code was removed
}
class ExceptionB extends ExceptionA{
// code was removed
}
class ExceptionC extends ExceptionA{
// code was removed
}
class ExceptionD extends ExceptionC{
// code was removed
A) The code written below throws an exception from the above hierarchy, depending on the value of c.
Fill in the 5 gaps below, so that a correct working program is created.
public void fooMethod (char c) {
try {
if (c ==' ') throw new Exception();
else if (c == 'a') throw new ExceptionD();
else if (c == 'b') throw new ExceptionC();
else if (c == 'c') throw new ExceptionA();
else if (c == 'd') throw new ExceptionB();
else c++;
}
catch (
System.out.println("A message related to this exception");
}
catch (
System.out.println("A message related to this exception");
}
catch (
System.out.println("A message related to this exception");
}
catch (
System.out.println("A message related to this exception");
}
catch (
System.out.println("A message related to this exception");
}
}
e) {
e) {
e) {
e) {
e ) {
Transcribed Image Text:We have created a hierarchy of exceptions like below: class ExceptionA extends Exception{ // code was removed } class ExceptionB extends ExceptionA{ // code was removed } class ExceptionC extends ExceptionA{ // code was removed } class ExceptionD extends ExceptionC{ // code was removed A) The code written below throws an exception from the above hierarchy, depending on the value of c. Fill in the 5 gaps below, so that a correct working program is created. public void fooMethod (char c) { try { if (c ==' ') throw new Exception(); else if (c == 'a') throw new ExceptionD(); else if (c == 'b') throw new ExceptionC(); else if (c == 'c') throw new ExceptionA(); else if (c == 'd') throw new ExceptionB(); else c++; } catch ( System.out.println("A message related to this exception"); } catch ( System.out.println("A message related to this exception"); } catch ( System.out.println("A message related to this exception"); } catch ( System.out.println("A message related to this exception"); } catch ( System.out.println("A message related to this exception"); } } e) { e) { e) { e) { e ) {
Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY