Test #2 Review: Chapters 7-10

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

For the following code, how many times would the while loop execute? StringTokenizer strToken = new StringTokenizer("Ben and Jerry's ice cream is great."); while (strToken.hasMoreTokens( )) { System.out.println(strToken.nextToken( )); } A. 1 B. 3 C. 5 D. 7

D. 7

Assuming the following declaration exists: enum Tree { OAK, MAPLE, PINE } What will the following code display? System.out.println(Tree.OAK); A. Tree.OAK B. 0 C. 1 D. OAK

D. OAK

The only limitation that static methods have is: A. They can refer to only non-static members of the class B. They can only be called from static members of the class C. They must be declared as public methods D. They cannot refer to non-static members of the class

D. They cannot refer to non-static members of the class

Look at the following code. Line 1: public class ClassA Line 2: { Line 3: public ClassA( ) { } Line 4:public void method1 (int a) {} Line 5: } Line 6: public class ClassB extends ClassA Line 7: { Line 8: public ClassB( ) { } Line 9: public void method1( ) { } Line 10: } Line 11: public class ClassC extends ClassB Line 12: { Line 13: public ClassC( ) { } Line 14: public void method1( ) { } Line 15: } Which method will be executed as a result of the following statements? ClassB item1 = new ClassA( ); item1.method1( ); A. Line 4 B. Line 9 C. Line 14 D. This is an error and will cause the program to crash

D. This is an error and will cause the program to crash

The ArrayList class is in this package. A. java.arraylist B. java.lang C. java.array D. java.util

D. java.util

If numbers is a two-dimensional array, which of the following would give the length of row r? A. numbers.length B. numbers.length[r] C. numbers[r].length[r] D. numbers[r].length

D. numbers[r].length

T or F: If two methods in the same class have the same name but different signatures, the second overrides the first.

False

T or F: Java limits the number of dimensions that an array may have to 15.

False

T or F: The String class's valueOf() method accepts a string representation as an argument and returns its equivalent integer value.

False

T or F: The names of the enum constants in an enumerated data type must be enclosed in quotation marks.

False

T or F: The this key word is the name of a reference variable that is available to all static methods.

False

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

In a class hierarchy:

The more general classes are toward the top of the tree and the more specialized are toward the bottom

What would be the results of the following code? int [ ] array1 = new int[25]; ... // Code that will put values in array1 int value = array1[0]; for (int a = 1; a < array1.length; a++) { if (array1[a] < value) value = array1[a]; }

value contains the lowest value in array1

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-14

How many rows and how many columns are in the points array, declared here: int [ ][ ] points = new int[10][20];

10 rows and 20 columns

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. 15 B. 16 C. 17 D. 18

A. 15

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. 456 B. ABC456 C. ABC D. abc456

A. 456

All fields declared in an interface: A. Are final and static B. Have protected access C. Must be initialized in the class implementing the interface D. Have private access

A. Are final and static

A search algorithm: A. Is a way to locate a specific item in a larger collection of data B. Is rarely used with arrays C. Arranges elements in ascending order D. Arranges elements in descending order

A. Is a way to locate a specific item in a larger collection of data

When the this variable is used to call a constructor: A. It must be the first statement in the constructor making the call B. It must be the last statement in the constructor making the call C. It can be anywhere in the constructor making the call D. You cannot use the this variable in a constructor call

A. It must be the first statement in the constructor making the call

When declaring class data members, it is best to declare them as: A. Private members B. Public members C. Protected members D. Restricted members

A. Private members

Two ways of concatenating two Strings are: A. Use the concat( ) method or use the + between the two Strings B. Use the concatenate( ) method or use the + between the two Strings C. Use the contenate( ) method or the concat( ) method D. Use the concat( ) method or the trim( ) method

A. Use the concat( ) method or use the + between the two Strings

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 Chicago, Trenton, and Tampa. D. We have lived in Chicago, Tampaon, and Atlanta.

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

In UML diagrams, inheritance is shown: A. With a line that has an open arrowhead at one end that points to the superclass B. With a line that has an open arrowhead at one end that points to the subclass C. With a line that has a closed arrowhead at one end that points to the superclass D. With a line that has a closed arrowhead at one end that points to the subclass

A. With a line that has an open arrowhead at one end that points to the superclass

Assume the class BankAccount has been created, and the following statement correctly creates an instance of the class: BankAccount account = new BankAccount(5000.0); What is true about the following statement? System.out.println(account); A. The method will display unreadable binary data on the screen. B. A compiler error will occur. C. The account object's toString method will be implicitly called. D. A runtime error will occur.

C. The account object's toString method will be implicitly called.

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

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

If ClassC is derived from ClassB, which is derived from ClassA, this would be an example of: A. Multiple inheritance B. A chain of inheritance C. A family tree D. Packaging

B. A chain of inheritance

What will be returned from the following method? public static float[] getValue(int x) A. A float value B. A reference to an array of float values C. An int value D. A reference to an array of integers

B. A reference to an array of float values

When a method's return type is a class, what is actually returned to the calling program? A. An object of that class B. A reference to an object of that class C. Only the values in the object that the method accessed D. Nothing, the return type is strictly for documentation in this situation

B. A reference to an object of that class

In the following statement, which is the superclass? public class ClassA extends ClassB implements ClassC A. ClassA B. ClassB C. ClassC D. Cannot tell

B. ClassB

Given the following statement, which of the following is not true? str.insert(8, 32); A. str is a StringBuilder type object B. The insert will start at position 32 C. The starting position for the insert is 8 D. The literal number 32 will be inserted

B. The insert will start at position 32

What is the value of str after the following code has been executed? String str; String sourceStr = "Hey diddle, diddle, the cat and the fiddle"; str = sourceStr.substring(12, 17); A. diddle B. diddl C. , didd D. Iddle

B. diddl

To convert the string, str = "285.74" to a double and store it in the variable 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, Double.parseDouble;

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

A deep copy of an object: A. is an assignment of that object to another object B. is an operation that copies an aggregate object, and all the objects it references C. is a bogus term, it has no meaning D. is always a private method

B. is an operation that copies an aggregate object, and all the objects it references

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

B. trim

What do you normally use with a partially-filled array? A. A class that does nothing but manage the array B. An accompanying parallel array C. An accompanying integer value that holds the number of items stored in the array D. An accumulator

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

In the following statement, which is the interface? public class ClassA extends ClassB implements ClassC A. ClassA B. ClassB C. ClassC D. Cannot tell

C. ClassC

In the following code, what will the call to super do? public class ClassB extends ClassA { public ClassB( ) { super(40); System.out.println("This is the last statement " + "in the constructor."); } } A. This cannot be determined form the above code B. It will call the method super and pass the value 40 to it as an argument C. It will call the constructor of ClassA that receives an integer as an argument D. The method super will have to be defined before we can say what will happen

C. It will call the constructor of ClassA that receives an integer as an argument

In an interface all methods have: A. Private access B. Protected access C. Public access D. Packaged access

C. Public access

To compare two objects in a class: A. Use the ==, e.g. object1 == object2 B. Write a method to do a byte-by-byte compare of the two objects C. Write an equals method that will make a field by field compare of the two objects D. Since objects consist of several fields, you cannot compare them

C. Write an equals method that will make a field by field compare of the two objects

What would be the results of the following code? final int SIZE = 25; int [ ] array1 = new int[SIZE]; ... // Code that will put values in array1 int value = 0; for (int a = 0; a < array1.length; a++) { value += array1[a] } A. value contains the highest value in array1 B. value contains the lowest value in array1 C. value contains the sum of all the values in array1 D. This would cause the program to crash

The test says the answer is A. value contains the highest value in array1, but this is false. The correct answer is C. value contains the sum of all the values in array1. So annoying...

T or F: A class's static methods do not operate on the fields that belong to any instance of the class.

True

T or F: An enumerated data type is actually a special type of class.

True

T or F: If a class has a method named finalize, it is called automatically just before an instance of the class is destroyed by the garbage collector.

True

T or F: It is not possible for a superclass to call a subclass's method.

True

T or F: Objects in an array are accessed with subscripts, just like any other data type in an array.

True

T or F: To compare the contents of two arrays, you must compare the elements of the two arrays.

True

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");

str would equal "Little Jack Horner sat on the corner"

What would be the results of executing the following code? StringBuilder str = new StringBuilder(12); str.append("The cow"); str.append(" jumped over the "); str.append("moon.");

str would equal "The cow jumped over the moon."


Ensembles d'études connexes

"A Roosevelt" de Rubén Darío- Vocabulario

View Set

CSEC-246: 3.01 Reading Exam Study Set.

View Set

Chpt 3 Musculoskeletal System and Connective Tissue Part 2 True/False

View Set

UNIT: States and Changes Of Matter

View Set

Combo with "Audit and Assurance 14, 15, 23, 24

View Set

Chapter 13: Physical and cognitive development in middle adulthood.

View Set

Spanish: Verb Conjugation: Preterite Tense: Buscar

View Set