10.16 | Which of the following operators cannot be used in conjunction with a String object? Select the two correct answers. -
+ -
- -
+= -
. -
& |
10.17 | Which expression will extract the substring "kap" from a string defined by String str = "kakapo" ? Select the one correct answer. -
str.substring(2, 2) -
str.substring(2, 3) -
str.substring(2, 4) -
str.substring(2, 5) -
str.substring(3, 3) |
10.18 | What will be the result of attempting to compile and run the following code? class MyClass { public static void main(String[] args) { String str1 = "str1"; String str2 = "str2"; String str3 = "str3"; str1.concat(str2); System.out.println(str3.concat(str1)); } } Select the one correct answer. -
The code will fail to compile since the expression str3.concat(str1) will not result in a valid argument for the println() method. -
The program will print str3str1str2 when run. -
The program will print str3 when run. -
The program will print str3str1 when run. -
The program will print str3str2 when run. |
10.19 | What function does the trim() method of the String class perform? Select the one correct answer. -
It returns a string where the leading white space of the original string has been removed. -
It returns a string where the trailing white space of the original string has been removed. -
It returns a string where both the leading and trailing white space of the original string has been removed. -
It returns a string where all the white space of the original string has been removed. -
None of the above. |
10.20 | Which statements are true? Select the two correct answers. -
String objects are immutable. -
Subclasses of the String class can be mutable. -
All wrapper classes are declared final . -
All objects have a public method named clone() . -
The expression ((new StringBuffer()) instanceof String) is always true . |
10.21 | Which of these expressions are legal? Select the four correct answers. -
"co".concat("ol") -
("co" + "ol") -
('c' + 'o' + 'o' + 'l') -
("co" + new String('o' + 'l')) -
("co" + new String("co")) |
10.22 | What will be the result of attempting to compile and run the following code? public class RefEq { public static void main(String[] args) { String s = "ab" + "12"; String t = "ab" + 12; String u = new String("ab12"); System.out.println((s==t) + " " + (s==u)); } } Select the one correct answer. -
The code will fail to compile. -
The program will print false false when run. -
The program will print false true when run. -
The program will print true false when run. -
The program will print true true when run. |
10.23 | Which of these parameter lists have a corresponding constructor in the String class? Select the three correct answers. -
() -
(int capacity) -
(char[] data) -
(String str) |
10.24 | Which method is not defined in the String class? Select the one correct answer. -
trim() -
length() -
concat(String) -
hashCode() -
reverse() |
10.25 | Which statement concerning the charAt() method of the String class is true? Select the one correct answer. -
The charAt() method takes a char value as an argument. -
The charAt() method returns a Character object. -
The expression ("abcdef").charAt(3) is illegal. -
The expression "abcdef".charAt(3) evaluates to the character 'd' . -
The index of the first character is 1. |
10.26 | Which expression will evaluate to true ? Select the one correct answer. -
"hello: there!".equals("hello there") -
"HELLO THERE".equals("hello there") -
("hello".concat("there")).equals("hello there") -
"Hello There".compareTo("hello there") == 0 -
"Hello there".toLowerCase().equals("hello there") |
10.27 | What will the following program print when run? public class Search { public static void main(String[] args) { String s = "Contentment!"; int middle = s.length()/2; String nt = s.substring(middle-1, middle+1); System.out.println(s.lastIndexOf(nt, middle)); } }; Select the one correct answer. -
2 -
4 -
5 -
7 -
9 -
11 |