Hello I want to check my answers for some multiple choice questions I was given. Any feed back will help. I highlighted my choices
1. An abstract class can contain ____.
a. only abstract methods c. abstract and non-abstract methods
b. only 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 statements is NOT true about creating your own exceptions?
a. Typically, constructors are the only methods that you include when you define
your own exception class.
b. The exception class that you define extends either the class Throwable or one of
its subclasses.
c. If you have created an exception class, you can define other exception classes
extending the definition of the exception class you created.
d. You must throw your own exceptions using the throw statement.
5. Which of the following is the default layout manager for a Java application?
a. null c. FlowLayout
b. GridLayout d. BorderLayout
6. In which of the following layout managers do all rows (columns) have the same number of
components and all components have the same size?
a. GridLayout c. BorderLayout
b. FlowLayout
d. EvenLayout
7 ? 9 Base on the following code :
int number;
boolean done = false;
do
{
try
{
System.out.print("Enter an integer: ");
number = console.nextInt();
System.out.println();
done = true;
System.out.println("number = " + number);
}
catch (InputMismatchException imeRef)
{
str = console.next();
System.out.println("Exception "
+ imeRef.toString()
+ " " + str);
}
}
while (!done);
7. Which exception-handling technique is the code above using?
a. Terminate the program c. Log the error and continue
b. Fix the error and continue d. None of the above
8. What is most likely the type of exception in the code above?
a. IllegalArgumentException c. FileNotFoundException
b. InputMismatchException d. NumberFormatException
9. How many times will the code in the try block above execute?
a. Until the user specifies that he/she wants to quit the program
b. Until the user inputs a valid integer
c. If there is an exception thrown it will execute just once because the program will
terminate at that point.
d. Zero times; the program will terminate before it reaches the try block.
10. 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.
11. 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.
12. An exception that can be analyzed by the compiler is a(n) ____.
a. unchecked exception c. compiler exception
b. checked exception d. execution exception
13. Which class of exceptions is NOT checked?
a. FileNotFoundException c. RuntimeException
b. ArithmeticException d. All exceptions are checked.
14. Which of the following is NOT a typical action of the catch block?
a. Completely handling the exception
b. Partially processing of the exception
c. Rethrowing the same exception for the calling environment
d. Throwing the exception
15- 17 Base 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());
}
}
}
15. 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.
16. Which of the following inputs would be caught by the second catch block in the program
above?
a. 0
c. h3
b. 10 d. -1
17. Which method throws the second exception in the code above?
a. nextInt c. println
b. toString d. nextLine
18. Which of the following methods prints a list of the methods that were called before the
exception was thrown?
a. getMessage()
c. printStackTrace()
b. printCalledMethods() d. traceMethodStack()
19. What can a method do with a checked exception?
a. Check the exception or ignore it.
b. Return the exception to the sender or handle it in a catch block.
c. Throw the exception to the method that called this method, or handle the
exception in a catch block.
d. Handle the exception in the try block or handle the exception in the catch
block.
20. For the interface WindowListener that contains more than one method, Java provides the
class ____.
a. MouseAdapter c. KeyListener
b. WindowAdapter d. KeyAdapter
21. 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.
22. . 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
23. When an object is thrown
a. it is deleted and can no longer be used
b. execution resumes with the next executable statement
c. control passes to a catch-block
d. the object is unavailable until the catch-block finishes execution
24. 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.
25. 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