Java: An Introduction to Problem Solving and Programming (8th Edition)
Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
Author: Walter Savitch
Publisher: PEARSON
Expert Solution & Answer
Book Icon
Chapter 9.2, Problem 20STQ

Explanation of Solution

Changing “DoubleException” to “Exception” in the “catch” statement:

By giving “Exception” in the place of “DoubleException” in the “catch” statement will not affect the output of the program because, the modified part is same like the original program.

Program:

The modified “catch” statement is highlighted below.

DoubleException.java:

//Define a class

public class DoubleException extends Exception

{

    //Default constructor

    public DoubleException()

    {

        //Call the method from parent class

        super("Double exception thrown!");

    }

    //Parameterized constructor

    public DoubleException(String message)

    {

        //Call the parent class's method

        super(message + " " + message);

    }

}

Main.java:

//Define the main class

class Main

{

    //Define the main method

    public static void main(String[] args)

    {

        //Try block

        try

        {

            //Print the statement

System.out...

Blurred answer
Students have asked these similar questions
I am getting this error with the EXCEPTION
What is exception propagation? Give an example of a class that contains at least two methods, in which one method calls another. Ensure that the subordinate method will call a predefined Java method that can throw a checked exception. The subordinate method should not catch the exception. Explain how exception propagation will occur in your example.
Write a class TimeOfDay that uses the exception classes defined in the previous exercise. Give it a method setTimeTo(timeString) that changes the time if timeString corresponds to a valid time of day. If not, it should throw an exception of the appropriate type. [Java]

Chapter 9 Solutions

Java: An Introduction to Problem Solving and Programming (8th Edition)

Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education