CS II Chapter 10 Quiz

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

An aggregation relationship is usually represented as __________ in ___________. A. a data field/the aggregating class B. a data field/the aggregated class C. a method/the aggregating class D. a method/the aggregated class

A

Analyze the following code. class Test { public static void main(String[] args) { String s; System.out.println("s is " + s); } } A. The program has a compile error because s is not initialized, but it is referenced in the println statement. B. The program has a runtime error because s is not initialized, but it is referenced in the println statement. C. The program has a runtime error because s is null in the println statement. D. The program compiles and runs fine

A

BigInteger and BigDecimal are immutable A. true B. false

A

In JDK 1.5, you may directly assign a primitive data type value to a wrapper object. This is called ______________. A. auto boxing B. auto unboxing C. auto conversion D. auto casting

A

The following program displays __________. public class Test { public static void main(String[] args) { String s = "Java"; StringBuilder buffer = new StringBuilder(s); change(s); System.out.println(s); } private static void change(String s) { s = s + " and HTML"; } } A. Java B. Java and HTML C. and HTML D. nothing is displayed

A

The StringBuilder methods _____________ not only change the contents of a string buffer, but also returns a reference to the string buffer. A. delete B. append C. insert D. reverse E. replace

A, B, C, D and E

Which of the following classes are immutable? A. Integer B. Double C. BigInteger D. BigDecimal E. String

A, B, C, D and E

Which of the following statements will convert a string s into i of int type? A. i = Integer.parseInt(s); B. i = (new Integer(s)).intValue(); C. i = Integer.valueOf(s).intValue(); D. i = Integer.valueOf(s); E. i = (int)(Double.parseDouble(s));

A, B, C, D and E

Suppose s1 and s2 are two strings. Which of the following statements or expressions are incorrect? A. String s = new String("new string"); B. String s3 = s1 + s2 C. s1 >= s2 D. int i = s1.length E. s1.charAt(0) = '5'

C, D and E

Assume s is " abc ", the method __________ returns a new string "abc". A. s.trim(s) B. trim(s) C. String.trim(s) D. s.trim()

D

To create an instance of BigDecimal for 454.45, use A. BigInteger(454.45); B. new BigInteger(454.45); C. BigInteger("454.45"); D. new BigDecimal("454.45");

D

To create an instance of BigInteger for 454, use A. BigInteger(454); B. new BigInteger(454); C. BigInteger("454"); D. new BigInteger("454");

D

What is displayed by the following code? System.out.print("Hi, ABC, good".matches("ABC ") + " "); System.out.println("Hi, ABC, good".matches(".*ABC.*")); A. false false B. true false C. true true D. false true

D

What is the output of the following code? String s = "University"; s.replace("i", "ABC"); System.out.println(s); A. UnABCversity B. UnABCversABCty C. UniversABCty D. University

D

Which of the following statements will convert a string s into a double value d? A. d = Double.parseDouble(s); B. d = (new Double(s)).doubleValue(); C. d = Double.valueOf(s).doubleValue(); D. All of the aboveD

D

What is the output of the following code? public class Test { public static void main(String[] args) { java.math.BigInteger x = new java.math.BigInteger("3"); java.math.BigInteger y = new java.math.BigInteger("7"); x.add(y); System.out.println(x); } } A. 3 B. 4 C. 10 D. 11

A

What is the output of the following code? public class Test { public static void main(String[] args) { String s1 = "Welcome to Java!"; String s2 = "Welcome to Java!"; if (s1 == s2) System.out.println("s1 and s2 reference to the same String object"); else System.out.println("s1 and s2 reference to different String objects"); } } A. s1 and s2 reference to the same String object B. s1 and s2 reference to different String objects

A

What is the output of the following code? public class Test { public static void main(String[] args) { String s1 = "Welcome to Java!"; String s2 = s1; if (s1 == s2) System.out.println("s1 and s2 reference to the same String object"); else System.out.println("s1 and s2 reference to different String objects"); } } A. s1 and s2 reference to the same String object B. s1 and s2 reference to different String objects

A

What is the output of the following code? public class Test { public static void main(String[] args) { String s1 = new String("Welcome to Java!"); String s2 = new String("Welcome to Java!"); if (s1.equals(s2)) System.out.println("s1 and s2 have the same contents"); else System.out.println("s1 and s2 have different contents"); } } A. s1 and s2 have the same contents B. s1 and s2 have different contents

A

Which of the following statements is preferred to create a string "Welcome to Java"? A. String s = "Welcome to Java"; B. String s = new String("Welcome to Java"); C. String s; s = "Welcome to Java"; D. String s; s = new String("Welcome to Java");

A

_________ returns the last character in a StringBuilder variable named strBuf? A. strBuf.charAt(strBuf.length() - 1) B. strBuf.charAt(strBuf.capacity() - 1) C. StringBuilder.charAt(strBuf.length() - 1) D. StringBuilder.charAt(strBuf.capacity() - 1)

A

___________ is attached to the class of the composing class to denote the aggregation relationship with the composed object. A. An empty diamond B. A solid diamond C. An empty oval D. A solid oval

A

Which of the following statements are correct? A. new java.math.BigInteger("343"); B. new java.math.BigDecimal("343.445"); C. new java.math.BigInteger(343); D. new java.math.BigDecimal(343.445);

A and B

Which of the following statements convert a double value d into a string s? A. s = (new Double(d)).toString(); B. s = d; C. s = new Double(d).stringOf(); D. s = String.stringOf(d); E. s = d + "";

A and E

In JDK 1.5, analyze the following code. Line 1: Integer[] intArray = {1, 2, 3}; Line 2: int i = intArray[0] + intArray[1]; Line 3: int j = i + intArray[2]; Line 4: double d = intArray[0]; A. It is OK to assign 1, 2, 3 to an array of Integer objects in JDK 1.5. B. It is OK to automatically convert an Integer object to an int value in Line 2. C. It is OK to mix an int value with an Integer object in an expression in Line 3. D. Line 4 is OK. An int value from intArray[0] object is assigned to a double variable d

A, B, C and D

Which of the following is true? A. You can add characters into a string buffer. B. You can delete characters into a string buffer. C. You can reverse the characters in a string buffer. D. The capacity of a string buffer can be automatically adjusted

A, B, C and D

__________ returns a string. A. String.valueOf(123) B. String.valueOf(12.53) C. String.valueOf(false) D. String.valueOf(new char[]{'a', 'b', 'c'})

A, B, C and D

Assume s is "ABCABC", the method __________ returns an array of characters. A. toChars(s) B. s.toCharArray() C. String.toChars() D. String.toCharArray() E. s.toChars()

B

The following program displays __________. public class Test { public static void main(String[] args) { String s = "Java"; StringBuilder buffer = new StringBuilder(s); change(buffer); System.out.println(buffer); } private static void change(StringBuilder buffer) { buffer.append(" and HTML"); } } A. Java B. Java and HTML C. and HTML D. nothing is displayed

B

What is displayed by the following code? String[] tokens = "A,B;C;D".split("[,;]"); for (int i = 0; i < tokens.length; i++) System.out.print(tokens[i] + " "); A. A,B;C;D B. A B C D C. A B C;D D. A B;C;D

B

What is the output of Integer.parseInt("10", 2)? A. 1; B. 2; C. 10; D. Invalid statement;

B

What is the output of the following code? public class Test { public static void main(String[] args) { String s1 = new String("Welcome to Java!"); String s2 = new String("Welcome to Java!"); if (s1 == s2) System.out.println("s1 and s2 reference to the same String object"); else System.out.println("s1 and s2 reference to different String objects"); } } A. s1 and s2 reference to the same String object B. s1 and s2 reference to different String objects

B

What is the output of the following code? public class Test { public static void main(String[] args) { String s1 = new String("Welcome to Java"); String s2 = s1; s1 += "and Welcome to HTML"; if (s1 == s2) System.out.println("s1 and s2 reference to the same String object"); else System.out.println("s1 and s2 reference to different String objects"); } } A. s1 and s2 reference to the same String object B. s1 and s2 reference to different String objects

B

Which of the following is the correct statement to return a string from an array a of characters? A. toString(a) B. new String(a) C. convertToString(a) D. String.toString(a)

B

Analyze the following code. class Test { public static void main(String[] args) { StringBuilder strBuf = new StringBuilder(4); strBuf.append("ABCDE"); System.out.println("What's strBuf.charAt(5)? " + strBuf.charAt(5)); } } A. The program has a compile error because you cannot specify initial capacity in the StringBuilder constructor. B. The program has a runtime error because because the buffer's capacity is 4, but five characters "ABCDE" are appended into the buffer. C. The program has a runtime error because the length of the string in the buffer is 5 after "ABCDE" is appended into the buffer. Therefore, strBuf.charAt(5) is out of range. D. The program compiles and runs fine.

C

Assume StringBuilder strBuf is "ABCDEFG", after invoking _________, strBuf contains "ABCRRRRDEFG". A. strBuf.insert(1, "RRRR") B. strBuf.insert(2, "RRRR") C. strBuf.insert(3, "RRRR") D. strBuf.insert(4, "RRRR")

C

Assume StringBuilder strBuf is "ABCDEFG", after invoking _________, strBuf contains "AEFG". A. strBuf.delete(0, 3) B. strBuf.delete(1, 3) C. strBuf.delete(1, 4) D. strBuf.delete(2, 4)

C

To divide BigDecimal b1 by b2 and assign the result to b1, you write _________. A. b1.divide(b2); B. b2.divide(b1); C. b1 = b1.divide(b2); D. b1 = b2.divide(b1); E. b2 = b2.divide(b1);

C

What is displayed by the following code? System.out.print("A,B;C".replaceAll(",;", "#") + " "); System.out.println("A,B;C".replaceAll("[,;]", "#")); A. A B C A#B#C B. A#B#C A#B#C C. A,B;C A#B#C D. A B C A B C

C

What is displayed by the following code? public static void main(String[] args) { String[] tokens = "Welcome to Java".split("o"); for (int i = 0; i < tokens.length; i++) { System.out.print(tokens[i] + " "); } } A. Welcome to Java B. Welc me to Java C. Welc me t Java D. Welcome t Java

C

What is displayed by the following statement? System.out.println("Java is neat".replaceAll("is", "AAA")); A. JavaAAAneat B. JavaAAA neat C. Java AAA neat D. Java AAAneat

C

What is the output of the following code? public class Test { public static void main(String[] args) { String s1 = new String("Welcome to Java!"); String s2 = s1.toUpperCase(); if (s1 == s2) System.out.println("s1 and s2 reference to the same String object"); else if (s1.equals(s2)) System.out.println("s1 and s2 have the same contents"); else System.out.println("s1 and s2 have different contents"); } } A. s1 and s2 reference to the same String object B. s1 and s2 have the same contents C. s1 and s2 have different contents

C

To add BigInteger b1 to b2, you write _________. A. b1.add(b2); B. b2.add(b1); C. b2 = b1.add(b2); D. b2 = b2.add(b1); E. b1 = b2.add(b1);

C and D

Assume s is "ABCABC", the method __________ returns a new string "aBCaBC". A. s.toLowerCase(s) B. s.toLowerCase() C. s.replace('A', 'a') D. s.replace('a', 'A') E. s.replace("ABCABC", "aBCaBC")

C and E

Which of the following statements is correct? A. Integer.parseInt("12", 2); B. Integer.parseInt(100); C. Integer.parseInt("100"); D. Integer.parseInt(100, 16); E. Integer.parseInt("345", 8);

C and E

Assume StringBuilder strBuf is "ABCCEFC", after invoking _________, strBuf contains "ABTTEFT". A. strBuf.replace('C', 'T') B. strBuf.replace("C", "T") C. strBuf.replace("CC", "TT") D. strBuf.replace('C', "TT") E. strBuf.replace(2, 7, "TTEFT")

E


संबंधित स्टडी सेट्स

PC Pro 4.6.7 Device Driver Installation Facts

View Set

Physics Module 4: Section 1 - Resistance, Resistivity and Ohm's Law

View Set

Unit 2 Test STA 2023 McGraw Hill

View Set

PEDS-Nursing Care of Children ATI (Dynamics test bank):

View Set

Polymers: Combinations of Monomers: Tutorial

View Set

14 differential reinforcement live action

View Set