Chapter07

advertisement
Chapter 7
30 questions
10 fill in the blank
10 true/false
10 multiple choice
Fill in the Blank Questions
1. String __________ has the effect of joining two strings together to form a single string.
[concatenation]
2. Strings are indexed starting at __________.
[0]
3. Java uses __________ collection to automatically remove object’s that are no longer referenced.
[garbage]
4. The __________ class does not recreate a new string for each modification.
[StringBuffer]
5. A String can be broken into a collection of tokens separated by delimiters using a __________ object.
[StringTokenizer]
6. The type of cipher known as __________ cipher rearranges the letters in a systematic way.
[transposition]
7. When encrypting messages, the unencrypted, readable message is called __________.
[plaintext]
8. If a subclass of an abstract class implements only some of the abstract methods it must be declared
__________.
[abstract]
9. Encrypted information that is in an unreadable format is called __________.
[ciphertext]
10. A string __________ is a series of characters enclosed in double quotes.
[literal]
True/False Questions
1.
A string literal is a sequence of zero or more characters contain in double quotes.
TRUE
FALSE
[TRUE]
2.
A string cannot be used in an assignment statement.
TRUE
FALSE
[FALSE]
3.
The lastIndexOf() method searches from left the right for a character or substring.
TRUE
FALSE
[FALSE]
4.
The empty string precedes all other strings in lexicographic order.
TRUE
FALSE
[TRUE]
5.
StringTokenizer class breaks strings into tokens using only the space as a delimiter.
TRUE
FALSE
[FALSE]
A subclass of an abstract class must implement at least one of the superclass’s abstract methods.
TRUE
FALSE
[FALSE]
6.
7.
An abstract class cannot be instantiated by declaring an instance of that type.
TRUE
FALSE
[TRUE]
8. When the == operator is used with two strings, true is returned if the two references designate the same
String.
TRUE
FALSE
[TRUE]
9.
Two Strings are equal if they store the same string value.
TRUE
FALSE
[TRUE]
10. Once a String has been instantiated, it cannot be altered in any way.
TRUE
FALSE
[TRUE]
Multiple-Choice Questions
1.
If the method indexOf() cannot find the character or substring passed, it returns
A.
B.
C.
D.
0
-1
the length of the string
9999
[B]
2.
What value is returned by the lastIndexOf() method?
String s = "The first bug was a moth";
System.out.println(s.lastIndexOf('t'));
A.
B.
C.
D.
8
9
23
22
[D]
3.
[A]
What statement retrieves the last character from a string str?
A. str.CharAt(str.length()-1);
B. str.CharAt(str.length());
C. str.CharAt(-1);
D. str.CharAt(0);
4.
What is printed from the following code?
String s = "JavaTest";
System.out.println(s.substring(3,5));
A.
D.
E.
D.
va
vaT
Ate
aT
[D]
5.
The __________ method is used to convert a nonstring item into a String.
A. equals()
B. valueOf()
C. indexOf()
D. charAt()
[B]
6.
What method is used to determine if there are any more tokens in the list?
A. nextToken()
B. StringTokenizer()
C. hasMoreTokens()
D. length()
[C]
7. What class is used to instantiate a string that can be altered without creating a reference that can no
longer be used in the program?
A. String
B. StringTokenizer
C. Token
D. StringBuffer
[D]
8.
What is printed from the following code?
String s = "Happy Birthday";
System.out.println(s.indexOf(s.charAt(11)));
A.
F.
G.
D.
[D]
day
hda
10
11
9.
What is printed from the following code?
String s = "To-be-or/not-to-be";
StringTokenizer sTokenizer = new StringTokenizer(s);
while (sTokenizer.hasMoreTokens()) {
System.out.println(sTokenizer.nextToken());
}
A.
B.
C.
D.
To be or not to be
To-be-or-not-to-be
To-be-or
To-be-or/not-to-be
[D]
10. What method is used to return a single character at a particular index position?
A. charAt()
B. indexAt()
C. charOf()
D. indexOf()
[A]
Download