ITP 120 Final

¡Supera tus tareas y exámenes ahora con Quizwiz!

By default, Java initializes array elements with what value?

0

A subclass can directly access:

Only public and protected members of the superclass

For the following code, what would be the value of str[2]? String[] str = {"abc", "def", "ghi", "jkl"};

a reference to the String "ghi"

A ragged array is:

a two-dimensional array where the rows are of different lengths

A(n) ________ is an object that is generated in memory as the result of an error or an unexpected event.

exception

The do-while loop is a pre-test loop.

false

In a try/catch construct, after the catch statement is executed:

the program resumes at the statement that immediately follows the try/catch construct

If a superclass does not have a default constructor or a no-arg constructor:

then a class that inherits from it, must call one of the constructors that the superclass does have

All exceptions are instances of classes that extend this class.

throwable

Which of the following are pre-test loops?

while, for

It is common practice to use a ________ variable as a size declarator.

final

Assuming that inputFile references a Scanner object that was used to open a file, which of the following statements will read an int from the file?

int number = inputFile.nextInt();

Subscript numbering always starts at what value?

0

All of the exceptions that you will handle are instances of classes that extend this class.

Exception

The exception classes are in packages in the ________.

Java API

In memory, an array of String objects:

consists of elements, each of which is a reference to a String object

Replacing inadequate superclass methods with more suitable subclass methods is known as what?

method overriding

If two methods have the same name but different signatures, they are:

overloaded

When you open a file with the PrintWriter class, the class can potentially throw an IOException.

true

When you pass the name of a file to the PrintWriter constructor, and the file alreadyexists, it will be erased and a new empty file with the same name will be created

true

The catch clause:

all of these

If final int SIZE = 15 and int[] x = new int[SIZE], what would be the range of subscript values that could be used with x[]?

0 through 14

This annotation tells the Java compiler that a method is meant to override a method in the superclass.

@Override

What do you normally use with a partially-filled array?

An accompanying integer value that holds the number of items stored in the array

If a subclass constructor does not explicitly call a superclass constructor:

Java will automatically call the superclass's default or no-arg constructor just before the code in the subclass's constructor executes

The numeric classes' "parse" methods all throw an exception of this type if the string being converted does not contain a convertible numeric value.

NumberFormatException

A protected member of a class may be directly accessed by:

all of these

When an array is passed to a method:

all of these (a reference to the array is passed, it is passed just as an object, the method has direct access to the original array)

What will be the result of executing the following code? int[] x = {0, 1, 2, 3, 4, 5};

an array of 6 values ranging from 0 through 5 and referenced by the variable x will be created

What will be returned from the following method? public static float[] getValue(int x)

an array of float values

Java performs ________, which means that it does not allow a statement to use a subscript that is outside the range of valid subscripts for the array.

array bounds checking

Given the following statement, which statement will write "Calvin" to the file DiskFile.txt? PrintWriter diskOut = new PrintWriter("DiskFile.txt");

diskOut.println("Calvin");

If the code in a method can potentially throw a checked exception, then that method must:

either handle the exception or have a throws clause listed in the method header

When the break statement is encountered in a loop, all the statements in the body of the loop that appear after it are ignored, and the loop prepares for the next iteration.

false

When a method is declared with the ________ modifier, it cannot be overridden in a subclass.

final

The try statement may have an optional ________ clause, which must appear after all of the catch clauses.

finally

Classes that inherit from the Error class are:

for exceptions that are thrown when a critical error occurs, and the application program should not try to handle them

An exception's default error message can be retrieved using this method.

getMessage()

The following catch statement can: catch (Exception e) {...}

handle all exceptions that are instances of the Exception class or a subclass of Exception

When using the PrintWriter class, which of the following import statements would you write near the top of your program?

import java.io.*;

________ is the process of inspecting data given to the program by the user and determining if it is valid.

input validation

Which of the following is a valid declaration for a ragged array?

int[][] ragged = new int[5][];

A sentinel value ________ and signals that there are no more values to be entered.

is a special value that cannot be mistaken as a member of the list

A search algorithm:

is a way to locate a specific item in a larger collection of data

In a catch statement, what does the following code do? System.out.println(e.getMessage());

it prints the error message for an exception

Each array in Java has a public field named ________ that contains the number of elements in the array.

length

To return an array of long values from a method, use this as the return type for the method.

long[]

This variable controls the number of times that the loop iterates.

loop control variable

The ability to catch multiple types of exceptions with a single catch is known as ________, and was introduced in Java 7.

multi-catch

If numbers is a two-dimensional array, which of the following would give the length of row r?

numbers[r].length

If you do not provide an access specifier for a class member, the class member is given ________ access by default.

package

A subclass may call an overridden superclass method by:

prefixing its name with the super key word and a dot (.)

Which of the following statements declares Salaried as a subclass of PayType?

public class Salaried extends PayType

Which of the following is a correct method header for receiving a two-dimensional array as an argument?

public static void passArray(int [][])

What do you call the number that is used as an index to pinpoint a specific element within an array?

subscript

What key word can you use to call a superclass constructor explicitly?

super

You can use this method to determine whether a file exists.

the File class's exists method

In order to do a binary search on an array:

the array must first be sorted in ascending order

Given the following two-dimensional array declaration, which statement is TRUE? int [][] numbers = new int [6] [9];

the array numbers has 6 rows and 9 columns

When an exception is thrown by code in the try block, the JVM begins searching the try statement for a catch clause that can handle it and passes control of the program to:

the first catch clause that can handle the exception

If the program does not handle an unchecked exception:

the program is halted and the default exception handler handles the exception

A file must always be opened before using it and closed when the program is finished using it.

true

The do-while loop must be terminated with a semicolon.

true

When the continue statement is encountered in a loop, all the statements in the body of the loop that appear after it are ignored, and the loop prepares for the next iteration.

true

You can use the PrintWriter class to open a file for writing and write data to it.

true

The sequential search algorithm:

uses a loop to sequentially step through an array, starting with the first element

Assume that inputFile references a Scanner object that was used to open a file. Which of the following while loops shows the correct way to read data from the file until the end of the file is reached?

while (inputFile.hasNext))

The binary search algorithm:

will cut the portion of the sorted array being search in half each time

If a class contains an abstract method:

you cannot create an instance of the class the method must be overridden in the subclass the method will have only a header, but not a body, and end with a semicolon

In a multi-catch, (introduced in Java 7) the exception types are separated in the catch clause by this symbol:

|

In the following statement, which is the subclass? public class ClassA extends ClassB implements ClassC

ClassA

In the following statement, which is the superclass? public class ClassA extends ClassB implements ClassC

ClassB

Which of the following will open a file named MyFile.txt and allow you to read data from it?

File file = new File("MyFile.txt"); Scanner inputFile = new Scanner(file);

Which of the following will open a file named MyFile.txt and allow you to append data to its existing contents?

FileWriter fwriter = new FileWriter("MyFile.txt", true); PrintWriter outFile = new PrintWriter(fwriter);

A loop that repeats a specific number of times is known as a(n):

counter-controlled loop


Conjuntos de estudio relacionados

Literary Terms for Year One Eng. Lit BA(hons)

View Set

PEDS Prep U Chapter 5: Growth and Development of the Preschooler

View Set

Med Surg 1 Ch45 Adaptive Quizzing

View Set

Give meanings for the following terms

View Set