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 19STQ

Explanation of Solution

Given program:

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.println("try block entered:");

            //Declare a variable

            int number = 42;

            //Check if the value is greater than 0

            if(number > 0)

        ...

Blurred answer
Students have asked these similar questions
Assume that the following code segment is executed. Which may occur when the run method of the program executes?
Time Converter 1. Write a program that converts dates from a numerical month-day format to alphabetic month-day format. IE 1/31 or 01/31 would have an output of January 31. 1. User enters the month and day as a single string. It is then converted. (10%) 2. Create 2 exception classes (20%) 1. MonthException thrown for invalid months 2. DayException-thrown for invalid days for the given month 3. You can assume Feb is always 28 days 2. This should run in a for loop and end when a user is done entering dates (70%)
1.public class Test{ public static void main(String args[]){ Person p = null; try{ } p.talk(); } catch (NullPointerException e) { System.out.print("There is a NullPointerException."); } catch(Exception e) { System.out.print("There is an Exception."); } System.out.print("Everything went fine."); } what will be the result if you run this program? O There is a NullPointerException. Everything went fine. O There is a NullPointerException. There is a NullPointerException. There is an Exception. This code will not compile, because in Java there are no pointers.

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
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning