While the Exception class is part of java.lang, IOException is part of java.io. - Answer
True
In order to have some code throw an exception, you would use which of the following
reserved words?
Correct Response
A) throw
B) Throwable
C) throws
D) try
E) goto - Answer Throw
The Scanner class provides an abstraction for input operations by
A) performing conversion operations from String to the appropriate type as specified in
the Scanner message
B) using try and catch statements to catch any IOException instead of throwing the
Exception elsewhere
C) parsing input lines into individual tokens
D) inputting from the standard input stream if create is called using System.in
Correct Response
E) all of the above - Answer All of the Above
Use the code below to answer the following questions. Note that the catch statements in
the code are not implemented, but you will not need those details. Assume filename is a
String, x is an int, a is a double array and i is an int. Use the comments i1, i2, i3, e1, e2,
e3, e4, e5 to answer the questions (i for instruction, e for exception handler).
try
{
BufferedReader infile = new BufferedReader(new FileReader(filename)); // i1
int x = Integer.parseInt(infile.readLine( )); // i2
a[++i] = (double) (1 / x); // i3
}
, catch (FileNotFoundException ex) {...} // e1
catch (NumberFormatException ex) {...} // e2
catch (ArithmeticException ex) {...} // e3
catch (ArrayIndexOutOfBounds ex) {...} // e4
catch (IOException ex) {...} // e5
An exception raised by the instruction in i1 would be caught by the catch statement
labeled
A) e5
B) e1
C) e2
Correct Answer
D) either e1 or e5
Incorrect Response
E) either e1, e4, or e5 - Answer D) either e1 or e5
While the Exception class is part of java.lang, IOException is part of java.io. - Answer
True
"class Aggregate" is incorrect. Choose the correct line so that this program prints
Granite: weight=25.0 value=4 numKind=7
public class Inherit
{
abstract class Stone
{
protected float weight = 13;
protected int value = 4;
abstract public String toString( );
}
class Aggregate
{
protected int numKind;
}
class Granite extends Aggregate
{
Granite( )
{