Comp. Sci. Chap 7-11

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

An exception's default error message can be retrieved using this method. A. getMessage() B. getErrorMessage() C. getDefaultMessage() D. getDefaultErrorMessage() Answer Key: A

A. getMessage()

Which of the following statements declares Salaried as a subclass of PayType? A. public class Salaried extends PayType B. public class Salaried implements PayType C. public class Salaried derivedFrom(Paytype) D. public class PayType derives Salaried Answer Key: A

A. public class Salaried extends PayType

Which of the following methods of the String class can be used to tokenize a string? A. split B. tokenize C. trim D. length Answer Key: A

A. split

Subscript or index numbering always starts at what value? A. 0 B. 1 C. -1 D. 2 Answer Key: A

Answer Key: A

All exceptions are instances of classes that extend this class. A. RunTimeException B. Throwable C. Error D. Exception Answer Key: B

B. Throwable

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. A. active array sequencing B. array bounds checking C. scope resolution binding D. buffer overrun protection Answer Key: B

B. array bounds checking

A(n) ________ is an object that is generated in memory as the result of an error or an unexpected event. A. acceptance B. exception C. default handler D. error message Answer Key: B

B. exception

Static methods can only operate on ________ fields. A. instance B. static C. global D. local Answer Key: B

B. static

When you are writing a program with String objects that may have unwanted spaces at the beginning or end of the strings, use this method to delete them. A. replace B. trim C. valueOf D. substring Answer Key: B

B. trim

In the following code, assume that inputFile references a Scanner object that has been successfully used to open a file: double totalIncome = 0.0; while (inputFile.hasNext()) { try { totalIncome += inputFile.nextDouble(); } catch(InputMismatchException e) { System.out.println("Non-numeric data encountered " + "in the file."); inputFile.nextLine(); } finally { totalIncome = 35.5; } } What will be the value of totalIncome after the following values are read from the file? 2.5 8.5 3.0 5.5 abc 1.0 A. 19.5 B. 0.0 C. 35.5 D. 75.0 Answer Key: C

C. 35.5

Replacing inadequate superclass methods with more suitable subclass methods is known as what? A. Method upgrading B. Tactical inheritance C. Method overriding D. Method overloading Answer Key: C

C. Method overriding

If the IOData.dat file does not exist, what will happen when the following statement is executed? RandomAccessFile randomFile = new RandomAccessFile("IOData.dat", "rw"); A. A FileNotFoundException will be thrown. B. An IOExcepton will be thrown. C. The file IOData.dat will be created. D. This is a critical error, the program will stop execution. Answer Key: C

C. The file IOData.dat will be created.

Each of the numeric wrapper classes has a static ________ method that converts a number to a string. A. GetString B. Parse C. ToString D. Convert Answer Key: C

C. ToString

Under Windows, which of the following statements will open the file InputFile.txt that is in the root directory on the C: drive? A. FileReader freader = new FileReader("C:\InputFile.txt"); B. FileReader freader = new FileReader("C:\InputFile\txt"); C. FileReader freader = new FileReader("/c/InputFile.txt"); D. FileReader freader = new FileReader("C:\\InputFile.txt"); Answer Key: D

D. FileReader freader = new FileReader("C:\\InputFile.txt");

Given that String[] str has been initialized, to change the first element of str with all characters converted to upper case, use the following statement: A. str.uppercase(); B. str[0].upperCase(); C. str.toUpperCase(); D. str[0].toUpperCase(); Answer Key: D

D. str[0].toUpperCase();

What will be the tokens for the following code? String str = "123-456-7890"; String[] tokens = str.split("-"); A. 123, 456, and 7890 B. - C. 123, 456, 7890, and - D. 123, 456, and 789 Answer Key: A

A. 123, 456, and 7890

To read data from a binary file you create objects from the following classes: A. FileInputStream and DataInputStream B. File and PrintWriter C. File and Scanner D. BinaryFileReader and BinaryDataReader Answer Key: A

A. FileInputStream and DataInputStream

What is demonstrated by the following code? try { (try block statements . . .) } catch(NumberFormatException | IOException ex) { respondToError(); } A. Multi-catch, a catch clause that can handle more than one exception, beginning in Java 7 B. A catch clause that can handle either exception type, but not both C. A conditional catch clause prototype that uses an overloaded OR operator to bind exception types D. This code is not supported in any version of Java, an error will result. Answer Key: A

A. Multi-catch, a catch clause that can handle more than one exception, beginning in Java 7

What will be the value of str after the following statements are executed? StringBuilder str = new StringBuilder("We have lived in Chicago, " + "Trenton, and Atlanta."); str.replace(17, 24, "Tampa"); A. We have lived in Tampa, Trenton, and Atlanta. B. We have lived in Chicago, Tampa, and Atlanta. C. We have lived in Tampa Trenton, and Tampa. D. We have lived in Tampalanta. Answer Key: A

A. We have lived in Tampa, Trenton, and Atlanta.

What would be the results of the following code? int[] x = { 55, 33, 88, 22, 99,11, 44, 66, 77 }; int a = 10; if(x[2] > x[5]) a = 5; else a = 8; A. a = 5 B. a = 8 C. a = 10 D. Error Answer Key: A

A. a = 5

Look at the following code: FileInputStream fstream = new FileInputStream("MyInfo.dat"); DataInputStream inputFile = new DataInputStream(fstream); This code can also be written as: A. FileInputStream inputFile = new FileInputStream(new DataInputStream("MyInfo.dat")); B. DataInputStream inputFile = new DataInputStream(new FileInputStream("MyInfo.dat")); C. FileInputStream fstream = new DataInputStream("InputFile.txt"); D. DataInputStream inputFile = new DataInputStream("InputFile.txt"); Answer Key: B

B. DataInputStream inputFile = new DataInputStream(new FileInputStream("MyInfo.dat"));

To convert the string, str = "285.74" to a double x, use the following statement: A. double x = str; B. double x = Double.parseDouble(str); C. double x = Double.Double(str); D. double x = str.parseDouble; Answer Key: B

B. double x = Double.parseDouble(str);

To return an array of long values from a method, use this as the return type for the method. A. long B. long[] C. long[ARRAY_SIZE] D. []long Answer Key: B

B. long[]

When a field is declared static, there will be: A. a copy of the field in each class object B. only one copy of the field in memory C. a copy of the field for each static method in the class D. only two copies of the field in memory Answer Key: B

B. only one copy of the field in memory

Which of the following is a correct method header named passArray for receiving a two-dimensional array as an argument? A. public static void passArray(int[1,2]) B. public static void passArray(int [][]) C. public static void passArray(int[1],[2]) D. public static void passArray(int[], int[]) Answer Key: B

B. public static void passArray(int [][])

The term ________ commonly is used to refer to a string that is part of another string. A. strand B. substring C. character fragment D. nested string Answer Key: B

B. substring

This indicates the number of elements, or values, the array can hold. A. the new operator B. the array's size declarator C. the array's data type D. the version of Java Answer Key: B

B. the array's size declarator

What will the following code display? String input = "99#7"; int number; try { number = Integer.parseInt(input); } catch(NumberFormatException ex) { number = 0; } catch(RuntimeException ex) { number = 1; } catch(Exception ex) { number = -1; } System.out.println(number); A. 99 B. 7 C. 0 D. 1 Answer Key: C

C. 0

What would be the range of subscript values that could be used with x[]? final int SIZE = 15; int[] x = new int[SIZE]; A. 1 through 15 B. 1 through 14 C. 0 through 14 D. 0 through 15 Answer Key: C

C. 0 through 14

What will be the value of loc after the following code is executed? int loc; String str = "The cow jumped over the moon."; loc = str.indexOf("ov"); A. 5 B. 6 C. 15 D. 16 Answer Key: C

C. 15

What is the value of scores[2][3] in the following array? int [] [] scores = { {88, 80, 79, 92}, {75, 84, 93, 80}, {98, 95, 92, 94}, {91, 84, 88, 96} }; A. 84 B. 93 C. 94 D. 95 Answer Key: C

C. 94

What will be printed after the following code is executed? String str = "abc456"; int m = 0; while ( m < 6 ) { if (Character.isLetter(str.charAt(m))) System.out.print( Character.toUpperCase(str.charAt(m))); m++; } A. abc456 B. ABC456 C. ABC D. 456 Answer Key: C

C. ABC

If your program needs to make a lot of changes to one or more string, you might consider using objects of this class: A. Character B. String C. StringBuilder D. CharArray Answer Key: C

C. StringBuilder

What is wrong with the following code? public class ClassB extends ClassA { public ClassB() { int init = 10; super(40); } } A. Nothing is wrong with the code. B. The method super is not defined. C. The call to the method super must be the first statement in the constructor. D. No values may be passed to super. Answer Key: C

C. The call to the method super must be the first statement in the constructor.

Assuming that str is declared as follows: String str = "RSTUVWXYZ"; What value will be returned from str.charAt(5)? A. U B. V C. W D. X Answer Key: C

C. W

What is term used for a class that is "wrapped around" a primitive data type and allows you to create objects instead of variables? A. Intrinsic class B. Enclosed object C. Wrapper class D. Transitional object Answer Key: C

C. Wrapper class

If your code does not handle and exception when it is thrown, this prints an error message and crashes the program. A. Java error handler B. multi-catch C. default exception handler D. try statement Answer Key: C

C. default exception handler

Each array in Java has a public field named ________ that contains the number of elements in the array. A. size B. capacity C. length D. limit Answer Key: C

C. length

What would be the results of executing the following code? StringBuilder str = new StringBuilder("Little Jack Horner "); str.append("sat on the "); str.append("corner"); A. str would reference "Little Jack Horner ". B. str would reference "Little Jac Horner sat on the ". C. str would reference "Little Jack Horner sat on the corner". D. The program would crash. Answer Key: C

C. str would reference "Little Jack Horner sat on the corner".

What key word can you use to call a superclass constructor explicitly? A. goto B. this C. super D. extends Answer Key: C

C. super


Ensembles d'études connexes

Chapter 23-The Disaster Management Cycle

View Set

Pathos Week 2 - Chapter 14: Neoplasia

View Set

Business Essentials Unit 4.0 Obj 4.01 SG

View Set

ch 16 blood vessels and circulation

View Set

Insulation and Ventilation Systems Set

View Set