面向对象程序设计(Java) chapter10

The following program displays C__.

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

}

}

单选题 (2 分) 2 分
A.
nothing is displayed

B.
and HTML

C.
Java

D.
Java and HTML
3.
The following program displays C__.

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

}

}

单选题 (2 分) 2 分
A.
nothing is displayed

B.
and HTML

C.
Java and HTML

D.
Java
4.
An aggregation(聚合) relationship is usually represented as __________ in ___________.

D
单选题 (2 分) 2 分
A.
a data field/the aggregated class

B.
a method/the aggregating class

C.
a method/the aggregated class

D.
a data field/the aggregating class
5.
The StringBuilder methods _____________ not only change the contents of a string buffer, but also returns a reference to the string buffer.

ABCDE
多选题 (2 分) 2 分
A.
insert

B.
reverse

C.
replace

D.
append

E.
delete
6.
What is the output of the following code?

String s = “University”;

s.replace(“i”, “ABC”);

System.out.println(s);

C
单选题 (2 分) 2 分
A.
UnABCversABCty

B.
UnABCversity

C.
University

D.
UniversABCty
7.
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];

ABCD
多选题 (2 分) 2 分
A.
It is OK to assign 1, 2, 3 to an array of Integer objects in JDK 1.5.

B.
It is OK to mix an int value with an Integer object in an expression in Line 3.

C.
It is OK to automatically convert an Integer object to an int value in Line 2.

D.
Line 4 is OK. An int value from intArray[0] object is assigned to a double variable d.
10.
Which of the following statements is preferred to create a string “Welcome to Java”?

A
单选题 (2 分) 2 分
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”);
12.
BigInteger and BigDecimal are immutable(不可变的)

B
判断题 (1 分) 1 分
A.
false

B.
true
13.
To divide BigDecimal b1 by b2 and assign the result to b1, you write _________.

A
单选题 (2 分) 2 分
A.
b1 = b1.divide(b2);

B.
b2 = b2.divide(b1);

C.
b1 = b2.divide(b1);

D.
b1.divide(b2);

E.
b2.divide(b1);
16.
Suppose s1 and s2 are two strings. Which of the following statements or expressions are incorrect?

ABE
多选题 (2 分) 2 分
A.
int i = s1.length

B.
s1 >= s2

C.
String s = new String(“new string”);

D.
String s3 = s1 + s2

E.
s1.charAt(0) = ‘5’
17.
Which of the following statements will convert a string s into a double value d? A

A
单选题 (2 分) 2 分
A.
All of the above.

B.
d = Double.valueOf(s).doubleValue();

C.
d = (new Double(s)).doubleValue();

D.
d = Double.parseDouble(s);
18.
What is the printout of the following code?

String s1 = "Welcome to Java";

String s2 = "Welcome to Java";

System.out.println("s1 == s2 is " + s1 == s2);

A
单选题 (2 分) 2 分
A.
false

B.
s1 == s2 is true

C.
true

D.
s1 == s2 is false
加号优先级高,相当于判断前面一块+s1是否等于s2
20.
Which of the following statements will convert a string s into i of int type?

ACDE
多选题 (2 分) 2 分
A.
i = Integer.parseInt(s);

B.
i = Integer.valueOf(s);

C.
i = Integer.valueOf(s).intValue();

D.
i = (new Integer(s)).intValue();

E.
i = (int)(Double.parseDouble(s));
23.
What is displayed by the following code?

System.out.print("Hi, ABC, good".matches("ABC ") + " ");

System.out.println("Hi, ABC, good".matches(".*ABC.*"));

B
单选题 (2 分) 2 分
A.
false false

B.
false true

C.
true true

D.
true false
String.matches() 这个方法主要是返回是否匹配指定的字符串,如果匹配则为true,否则为false;
25.
Which of the following classes are immutable?

ABCDE
多选题 (2 分) 2 分
A.
BigInteger

B.
Integer

C.
Double

D.
String

E.
BigDecimal
26.
To add BigInteger b1 to b2, you write _________.

AC
多选题 (2 分) 2 分
A.
b2 = b1.add(b2);

B.
b2.add(b1);

C.
b2 = b2.add(b1);

D.
b1 = b2.add(b1);

E.
b1.add(b2);
27.
Assume s is “ABCABC”, the method __________ returns an array of characters(字符数组).

B
单选题 (2 分) 2 分
A.
String.toCharArray()

B.
s.toCharArray()

C.
toChars(s)

D.
String.toChars()

E.
s.toChars()
29.
_________ returns the last character in a StringBuilder variable named strBuf?

C
单选题 (2 分) 2 分
A.
StringBuilder.charAt(strBuf.capacity() - 1)

B.
StringBuilder.charAt(strBuf.length() - 1)

C.
strBuf.charAt(strBuf.length() - 1)

D.
strBuf.charAt(strBuf.capacity() - 1)
31.
Which of the following statements convert a double value d into a string s?

A
单选题 (2 分) 2 分
A.
s = (new Double(d)).toString();

B.
s = new Double(d).stringOf();

C.
s = (Double.valueOf(s)).toString();

D.
s = String.stringOf(d);
32.
Which of the following is the correct statement to return a string from an array a of characters?

B
单选题 (2 分) 2 分
A.
String.toString(a)

B.
new String(a)

C.
toString(a)

D.
convertToString(a)
33.
Which of the following is an object?

ACD
多选题 (2 分) 2 分
A.
“abc”

B.
343

C.
new String(“abc”);

D.
new Date()
35.
Analyze the following code.

class Test {

public static void main(String[] args) {

String s;

System.out.println("s is " + s);

}

}

A
单选题 (2 分) 2 分
A.
The program has a compilation(编译) 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 compiles and runs fine.

D.
The program has a runtime error because s is null in the println statement.
Assume s is " abc ", the method __________ returns a new string “abc”.

C
单选题 (2 分) 2 分
A.
trim(s)

B.
String.trim(s)

C.
s.trim()

D.
s.trim(s)
39.
Assume StringBuilder strBuf is “ABCCEFC”, after invoking _________, strBuf contains “ABTTEFT”.

D
单选题 (2 分) 2 分
A.
strBuf.replace(‘C’, ‘T’)

B.
strBuf.replace(“CC”, “TT”)

C.
strBuf.replace(‘C’, “TT”)

D.
strBuf.replace(2, 7, “TTEFT”)

E.
strBuf.replace(“C”, “T”)
40.
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);

}

}

C
单选题 (2 分) 2 分
A.
11

B.
10

C.
3

D.
4
41.
What is the output of Integer.parseInt(“10”, 2)?

D
单选题 (2 分) 2 分
A.
1;

B.
10;

C.
Invalid statement;

D.
2;
42.
Which of the following statements is correct?

BD
多选题 (2 分) 2 分
A.
Integer.parseInt(“12”, 2);

B.
Integer.parseInt(“345”, 8);

C.
Integer.parseInt(100);

D.
Integer.parseInt(“100”);

E.
Integer.parseInt(100, 16);
43.
The method equals, compareTo, charAt, and length are in the _______ class.

ABD
多选题 (2 分) 2 分
A.
StringBuilder

B.
String

C.
Character

D.
StringBuffer
44.
___________ is attached to the class of the composing class to denote the aggregation relationship with the composed object.

D
单选题 (2 分) 2 分
A.
A solid oval

B.
An empty oval

C.
A solid diamond

D.
An empty diamond
45.
What is the print out of the following code?

String s = “Welcome to Java”;

s.replaceAll(“a”, “BB”);

System.out.println(s);

C
单选题 (2 分) 2 分
A.
Welcome to JavBB

B.
Welcome to JBBva

C.
Welcome to Java

D.
Welcome to JBBvBB
46.
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));

}

}

B
单选题 (2 分) 2 分
A.
The program has a runtime error because because the buffer’s capacity is 4, but five characters “ABCDE” are appended into the buffer.

B.
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.

C.
The program compiles and runs fine.

D.
The program has a compilation error because you cannot specify initial capacity in the StringBuilder constructor.
47.
What is displayed by the following code?

System.out.print("A,B;C".replaceAll(",;", "#") + " ");

System.out.println("A,B;C".replaceAll("[,;]", "#"));

C
单选题 (2 分) 2 分
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
48.
Which of the following is true?

ABCD
多选题 (2 分) 2 分
A.
The capacity of a string buffer can be automatically adjusted.(字符串缓冲区的容量可以自动调整

B.
You can reverse the characters in a string buffer.(您可以反转字符串缓冲区中的字符)

C.
You can delete characters into a string buffer.(您可以将字符删除到字符串缓冲区中。)

D.
You can add characters into a string buffer.(您可以将字符添加到字符串缓冲区中)
49.
In JDK 1.5, you may directly assign a primitive data type value to a wrapper object. This is called ______________.

B
单选题 (2 分) 2 分
A.
auto conversion

B.
auto boxing

C.
auto unboxing

D.
auto casting
50.
__________ returns a string.

ABCD
多选题 (2 分) 2 分
A.
String.valueOf(12.53)

B.
String.valueOf(false)

C.
String.valueOf(new char[]{‘a’, ‘b’, ‘c’})

D.
String.valueOf(123)
51.
Which of the following statements are correct?

BCD
多选题 (2 分) 2 分
A.
new java.math.BigInteger(343);

B.
new java.math.BigDecimal(“343.445”);

C.
new java.math.BigDecimal(343.445);

D.
new java.math.BigInteger(“343”);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值