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

Explanation of Solution

Given program:

IntException.java:

//Define a class

public class IntException extends Exception

{

    private int intMessage;

    //Default constructor

    public IntException()

    {

        //Call the parent class by passing the message

        super("IntException thrown!");

    }

    //Parameterized constructor

    public IntException(String message)

    {

        //Call the parent class by passing the message

        super(message + " " + message);

    }

    //Parameterized constructor

    public IntException(int number)

    {

        //Call the parent class by passing the message

        super("IntException thrown!");

        //Assign the value

        intMessage = number;

    }

    //Method to get the number

    public int getNumber()

    {

        //Return the value

        return intMessage;

    }

}

Main...

Blurred answer
Students have asked these similar questions
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.
JAVA PROGRAM Probloem: Define a new exception, called ExceptionLineTooLong, that prints out the error message "The strings is too long". Write a program that reads phrase and throws an exception of type ExceptionLineTooLong in the case where a string is longer than 80 characters. First Example:Input:The quick brown fox jumped over the lazy dogs.Output:The quick brown fox jumped over the lazy dogs. Second Example:Input: The quick brown fox jumped over the lazy dogs. The quick brown fox jumped over the lazy dogs.The quick brown fox jumped over the lazy dogs. The quick brown fox jumped over the lazy dogs.The quick brown fox jumped over the lazy dogs. The quick brown fox jumped over the lazy dogs.The quick brown fox jumped over the lazy dogs. The quick brown fox jumped over the lazy dogs.The quick brown fox jumped over the lazy dogs. The quick brown fox jumped over the lazy dogs.The quick brown fox jumped over the lazy dogs. The quick brown fox jumped over the lazy dogs.The quick brown…
Suppose the exception class CrazyException is defined as follows: public class CrazyException extends Exception { public CrazyException() { super("Crazy exception thrown!"); System.out.println("Wow, Crazy exception thrown!"); } public CrazyException(String message) { super(message); System.out.println("Wow, crazy exception thrown with "+ "an argument!"); } public void crazyMethod() { System.out.println("Message is " + getMessage()); } } What output would be produced by the following unlikely code? CrazyException exceptionObject = new CrazyException(); System.out.println(exceptionObject.getMessage()); exceptionObject.crazyMethod();

Chapter 9 Solutions

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

Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT