ITSC 1213 PRACTICE FINAL EXAM QUESTIONS AND
CORRECT ANSWERS
If the code inside a try block throws a FileNotFoundException and an IOException,
which of the following are correct ways of handling this (i.e. results in code that
compiles)? (Select all that apply)
Having multiple catch block starting with IOException followed by an
FileNotFoundException
Having one catch block that catches FileNotFoundException and declaring the method
to throw an IOException
Having one catch block that catches Exception
Having multiple catch block starting with FileNotFoundException followed by an
IOException
Having one catch block that catches FileNotFoundException
Having one catch block that catches IOException - Answers - Having multiple catch
block starting with FileNotFoundException followed by an IOException
An abstract class can be _____________.
instantiated
all of the above
extended
without constructor - Answers - extended
You define a class, Shape, and create an object of Shape called triangle. You do not
include a toString() method in Shape. Would the following code compile and execute
normally:
triangle.toString();
No. This code will cause a execution error, because you did not specifically inherit the
Object class.
No. This code will produce a compile error, because you did not specifically inherit the
Object class.
, Yes. Because Java will recognize that the method is missing and will automatically
generate the toString() method for you.
Yes. Because Shape inherits the Java class, Object. Object includes a toString()
method which is automatically inherited by your class, Shape. - Answers - Yes.
Because Shape inherits the Java class, Object. Object includes a toString() method
which is automatically inherited by your class, Shape.
An array can have several different types of data simultaneously.
false
true - Answers - False
Unit tests are statements that exercise some code and compare the computed result
with the expected result.
true
false - Answers - true
What does the following code do:
File file = new File("sample.txt");
Scanner fileReader = new Scanner(file);
while(fileReader.hasNext()) {
String line = fileReader.nextLine();
System.out.println(line);
}
The code prints the file sample.txt to a socket
The code prints the file sample.txt to the console
The code prints the file sample.txt to the standard error
The code copies the file sample.txt to another file - Answers - The code prints the file
sample.txt to the console
An array can hold multiple values of the same type of data.
false
true - Answers - true
CORRECT ANSWERS
If the code inside a try block throws a FileNotFoundException and an IOException,
which of the following are correct ways of handling this (i.e. results in code that
compiles)? (Select all that apply)
Having multiple catch block starting with IOException followed by an
FileNotFoundException
Having one catch block that catches FileNotFoundException and declaring the method
to throw an IOException
Having one catch block that catches Exception
Having multiple catch block starting with FileNotFoundException followed by an
IOException
Having one catch block that catches FileNotFoundException
Having one catch block that catches IOException - Answers - Having multiple catch
block starting with FileNotFoundException followed by an IOException
An abstract class can be _____________.
instantiated
all of the above
extended
without constructor - Answers - extended
You define a class, Shape, and create an object of Shape called triangle. You do not
include a toString() method in Shape. Would the following code compile and execute
normally:
triangle.toString();
No. This code will cause a execution error, because you did not specifically inherit the
Object class.
No. This code will produce a compile error, because you did not specifically inherit the
Object class.
, Yes. Because Java will recognize that the method is missing and will automatically
generate the toString() method for you.
Yes. Because Shape inherits the Java class, Object. Object includes a toString()
method which is automatically inherited by your class, Shape. - Answers - Yes.
Because Shape inherits the Java class, Object. Object includes a toString() method
which is automatically inherited by your class, Shape.
An array can have several different types of data simultaneously.
false
true - Answers - False
Unit tests are statements that exercise some code and compare the computed result
with the expected result.
true
false - Answers - true
What does the following code do:
File file = new File("sample.txt");
Scanner fileReader = new Scanner(file);
while(fileReader.hasNext()) {
String line = fileReader.nextLine();
System.out.println(line);
}
The code prints the file sample.txt to a socket
The code prints the file sample.txt to the console
The code prints the file sample.txt to the standard error
The code copies the file sample.txt to another file - Answers - The code prints the file
sample.txt to the console
An array can hold multiple values of the same type of data.
false
true - Answers - true