Part I True/False ( 40 points , 2 point each)
If you have created an exception class, you can define other exception classes extending the definition of the exception class you created.
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.
If a class is declared final, then no other class can be derived from this class.
The class Throwable contains constructor(s).
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.
Every program with a try block must end with a finally block.
If there is a finally block after the last catch block, the finally block always executes.
Making a reference to an object that has not yet been instantiated would throw an exception from the NullPointerException class.
If you have created an exception class, you can define other exception classes extending the efinition of the exception class you created.
The layout manager FlowLayout places components in the container from left to right until no more items can be placed.
The class Container is the superclass of all the classes designed to provide a GUI.
JTextAreas can be used to display multiple lines of text.
The StringIndexOutOfBoundsException could be thrown by the method parseInt of the class Integer.
The class RuntimeException is part of the package java.io.
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.
The order in which catch blocks are placed in a program has no impact on which catch block is executed.
The methods getMessage and printStackTrace are private methods of the class Throwable.
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.
If a member of a class is a method, it can (directly) access any member of the class.
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)
- An abstract class can contain ____.
a. only abstract methods
b. only non-abstract methods
c. abstract and non-abstract methods
d. nothing - 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 - 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 - Which of the following is the default layout manager for a Java application?
a. null
b. GridLayout
c. FlowLayout
d. BorderLayout - 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 - 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. - 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. - 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;
try
{
System.out.print("Enter dividend: ");
dividend = console.nextInt();
System.out.println();
System.out.print("Enter divisor: ");
divisor = console.nextInt();
System.out.println();
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());
}
- 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. - 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 - Which method throws the second exception in the code above?
a. nextInt
b. toString
c. println
d. nextLine - 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() - 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. - 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 - 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.