Programming Question

Discussion in 'OT Technology' started by morgue, Oct 31, 2006.

  1. morgue

    morgue New Member

    Joined:
    Jul 10, 2004
    Messages:
    8,278
    Likes Received:
    0
    I have this question on my assigment but I don't fully understand what they want me to do, it says:

    Use inheritance to create an exception superclass (called ExceptionA) and exception subclasses ExceptionB and ExceptionC, where ExceptionB inherits from ExceptionA and ExceptionC inherits from ExceptionB. Write a program to demonstrate that catch block for type ExceptionA catches exceptions of types ExceptionB and ExeptionC.

    So say I have class ExceptionA
    Code:
    import java.util.Scanner;
    
    public class ExceptionA 
    {
        public ExceptionA ( )
        {
            Scanner scanner = new Scanner( System.in );
            boolean continueLoop = true;
            
            do
                try
                {
                    System.out.print("Integer 10 divided by (Type an integer number a press Enter): ");
                    int denominator = scanner.nextInt();
                    System.out.printf("Result: %d\n", 10/denominator);
                    continueLoop = false;            
                } // end try
                catch ( ArithmeticException arithmeticException )
                {
                    System.err.printf( "\nException: %s\n", arithmeticException );
                    System.out.println("Zero is an invalid denominator. Please try again.\n" );
                }
            while (continueLoop);
        }
    }
    
    Now I'd need
    class ExceptionB extends ExceptionA
    class ExceptionC extends ExceptionB
    and class ExteptionTest (with the main)

    I don't understand... are they asking me to create a method or what?
     

Share This Page