Part I True/False ( 40 points , 2 point each)

  1. If you have created an exception class, you can define other exception classes extending the definition of the exception class you created.

  2. Using the mechanism of inheritance, every public member of the class Object can be overridden and/or invoked by every object of any class type.

  3. If a class is declared final, then no other class can be derived from this class.

  4. The class Throwable contains constructor(s).

  5. You can instantiate an object of a subclass of an abstract class, but only if the subclass gives the definitions of all the abstract methods of the superclass.

  6. Every program with a try block must end with a finally block.

  7. If there is a finally block after the last catch block, the finally block always executes.

  8. Making a reference to an object that has not yet been instantiated would throw an exception from the NullPointerException class.

  9. If you have created an exception class, you can define other exception classes extending the efinition of the exception class you created.

  10. The layout manager FlowLayout places components in the container from left to right until no more items can be placed.

  11. The class Container is the superclass of all the classes designed to provide a GUI.

  12. JTextAreas can be used to display multiple lines of text.

  13. The StringIndexOutOfBoundsException could be thrown by the method parseInt of the class Integer.

  14. The class RuntimeException is part of the package java.io.

  15. If an exception occurs in a try block and that exception is caught by a catch block, then the remaining catch blocks associated with that try block are ignored.

  16. The order in which catch blocks are placed in a program has no impact on which catch block is executed.

  17. The methods getMessage and printStackTrace are private methods of the class Throwable.

  18. If a formal parameter is a variable of a primitive data type, then after copying the value of the actual parameter, there is no connection between the formal parameter and actual parameter.

  19. If a member of a class is a method, it can (directly) access any member of the class.

  20. You must always use the reserved word super to use a method from the superclass in the subclass.

Part II Multiple Choice : (30 points, 2 points each)

  1. An abstract class can contain ____.
    a. only abstract methods
    b. only non-abstract methods
    c. abstract and non-abstract methods
    d. nothing
  2. An abstract method ____.
    a. is any method in the abstract class
    b. cannot be inherited
    c. has no body
    d. is found in a subclass and overrides methods in a superclass using the reserved word abstract
  3. If a class implements an interface, it must ____.
    a. provide definitions for each of the methods of the interface
    b. override all constants from the interface
    c. rename all the methods in the interface
    d. override all variables from the interface
  4. Which of the following is the default layout manager for a Java application?
    a. null
    b. GridLayout
    c. FlowLayout
    d. BorderLayout
  5. Java will automatically define a constructor
    a. if the programmer does not define a default constructor for a class
    b. if the programmer does not define any constructors for a class
    c. if the program refers to a constructor with no parameters
    d. for every class defined in a program
  6. How many finally blocks can there be in a try/catch structure?
    a. There must be 1.
    b. There can be 1 following each catch block.
    c. There can be 0 or 1 following the last catch block.
    d. There is no limit to the number of finally blocks following the last catch block.
  7. What happens in a method if there is an exception thrown in a try block but there is no catch block but a finally block following the try block?
    a. The program ignores the exception.
    b. The program will not compile without a complete try/catch structure.
    c. The program terminates immediately.
    d. The program throws an exception and proceeds to execute the finally block.
  8. An exception that can be analyzed by the compiler is a(n) ____.
    a. unchecked exception
    b. checked exception
    c. compiler exception
    d. execution exception

9 - 12 Based on the following code :

import java.util.*;

public class ExceptionExample1


    static Scanner console = new Scanner(System.in);

    public static void main(String[]  args)


        int dividend, divisor, quotient;



            System.out.print("Enter dividend: ");

            dividend = console.nextInt();


            System.out.print("Enter divisor: ");

            divisor = console.nextInt();


            quotient = dividend / divisor;

            System.out.println("quotient  = " + quotient);


              catch (ArithmeticException aeRef)


            System.out.println("Exception" + aeRef.toString());


              catch (InputMismatchException imeRef)


            System.out.println("Exception " 

                             + imeRef.toString());


        catch( IOException ioeRef)


           System.out.println("Exception "

                         + ioeRef.toString());

  1. Which of the following will cause the first exception to occur in the code above?
    a. if the divisor is zero
    b. if the dividend is zero
    c. if the quotient is zero
    d. This code will not compile so an exception cannot be triggered.
  2. Which of the following inputs would be caught by the second catch block in the program above?
    a. 0
    b. 10
    c. h3
    d. -1
  3. Which method throws the second exception in the code above?
    a. nextInt
    b. toString
    c. println
    d. nextLine
  4. Which of the following methods prints a list of the methods that were called before the exception was thrown?
    a. getMessage()
    b. printCalledMethods()
    c. printStackTrace()
    d. traceMethodStack()
  5. How would the three classes, Undergraduate, Graduate, and Student interrelate if we are determined to use inheritance in the class definitions?
    a. Student would be a subclass of Undergraduate, which would be a subclass of Graduate.
    b. Graduate would be a subclass of Undergraduate, which would be a subclass of Student.
    c. Graduate would be a subclass of Student, and Undergraduate would be a subclass of Graduate.
    d. Undergraduate and Graduate would both be subclasses of Student.
  6. Which of the following types of methods cannot be declared as abstract?
    a. Private methods
    b. Static methods
    c. a and b
    d. neither a nor b
  7. What happens when an expression uses == to compare two string variables?
    a. The value of the expression will be true if both strings have the same characters in them.
    b. The value of the expression will be true if both string variables refer to the same object.
    c. The expression will not be correct syntax and the program will not compile.
    d. A run-time error will occur.

Edited by mike_2000_17: Fixed formatting

8 Years
Discussion Span
Last Post by Ancient Dragon
This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.