Java题目集-Chapter 10 Object-Oriented Thinking
创始人
2024-04-10 11:30:36
0

一.单选题

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

答:空钻石运算符 (<>)附加到组合类的类,以表示与组合对象的聚合关系。

2.Assume StringBuilder strBuf is "ABCCEFC", after invoking ____E_____, 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")

答:假设 StringBuilder strBuf 是 “ABCCEFC”,调用______后,strBuf 包含 “ABTTEFT”

strBuf.replace(strat:  ,end:   ,str:   );

3.Assume StringBuilder strBuf is "ABCDEFG", after invoking _____B____, strBuf contains "ABCRRRRDEFG".

A.strBuf.insert(1, "RRRR")

B.strBuf.insert(2, "RRRR")

C.strBuf.insert(3, "RRRR")

D.strBuf.insert(4, "RRRR")

4.Assume StringBuilder strBuf is "ABCDEFG", after invoking ___C___, strBuf contains "AEFG".

A.strBuf.delete(0, 3)

B.strBuf.delete(1, 3)

C.strBuf.delete(1, 4)

D.strBuf.delete(2, 4)

答:将删除这个序列的一个子字符串中的字符,子字符串的开始在指定的start和延伸处的字符索引end - 1或结束的序列。

5.Which of the following is the correct statement to return a string from an array a of characters?______B______

A.toString(a)

B.new String(a)

C.convertToString(a)

D.String.toString(a)

答:以下哪项是从字符数组 a 返回字符串的正确语句

6.What is the output of the following code?___B____

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

7.What is the output of the following code?____A____

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

答:String str = "xxxxx"的实现过程:首先栈区创建str引用,然后在String池中寻找其指向的内容为"xxxxx"的对象,如果String池中没有,则创建一个,然后str指向String池中的对象,如果有,则直接将str指向"xxxxx"",不再重新创建对象;
8.What is the output of the following code?____A____

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

9.An aggregation relationship is usually represented as ______A______.

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

答:聚合关系通常表示为数据字段/聚合类

二.多选题

1.Which of the following statements will convert a string s into i of int type?____ABCDE_____

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

答:Integer.parseInt() 是Integer包装类下的一个方法,作用是将()内的String类型字符串转化为int类型【parseInt (1010,2) 意思就是:输出2进制数1010在十进制下的数.】;intValue ()方法用于返回此Integer对象表示的值,该值转换为int类型 (通过强制转换)。

2.Which of the following statements are correct?___ABD_____

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

答:常用构造函数

  1. BigDecimal(int)

    创建一个具有参数所指定整数值的对象

  2. BigDecimal(double)

    创建一个具有参数所指定双精度值的对象

  3. BigDecimal(long)

    创建一个具有参数所指定长整数值的对象

  4. BigDecimal(String)

    创建一个具有参数所指定以字符串表示的数值的对

常用构造函数

1、BigInteger(byte[] val)
这个构造函数用于转换一个字节数组包含BigInteger的二进制补码,以二进制表示成一个BigInteger。

(用字节数组中值的ASCII码构造BigInteger)

2、BigInteger(int signum, byte[] magnitude)
此构造函数用于将BigInteger的符号大小表示法转换成一个BigInteger值。

(和第一种一样,增加了符号:1,0,-1)

3、BigInteger(int bitLength, int certainty, Random rnd)
此构造函数用于构造一个随机生成正BigInteger的可能是以指定的bitLength的素数。

(bitLength:返回的 BigInteger 的 bitLength;

certainty:调用方允许的不确定性的度量。新的 BigInteger 表示素数的概率超出 (1 - 1/2certainty)。此构造方法的执行时间与此参数的值是成比例的;

rnd:随机比特源,用这些随机比特选择用来进行质数测试的候选数。)

4、BigInteger(int numBits, Random rnd)
此构造函数用于构造一个随机生成的BigInteger,范围在0到 (2numBits - 1), 包括边界值。

5、BigInteger(String val)
此构造函数用于将十进制的字符串转换成一个BigInteger值表示形式。

6、BigInteger(String val, int radix)
这个构造函数用于将指定基数的数值字符串转换为BigInteger表示形式。

3.To add BigInteger b1 to b2, you write ____CD_____.

A.b1.add(b2);

B.b2.add(b1);

C.b2 = b1.add(b2);

D.b2 = b2.add(b1);

E.b1 = b2.add(b1);

答:要将 BigInteger b1 添加到 b2

相关内容

热门资讯

阿索卡·塔诺为什么没有在星球大... 阿索卡·塔诺为什么没有在星球大战正传出现?阿索卡没有听说过,,是什么鬼阿索卡是阿纳金年轻时收的徒弟 ...
河北公布第二批美丽河湖名单,1... 转自:河北新闻网河北公布第二批美丽河湖名单,15个河湖入选全省美丽河湖总数达26个河北日报讯(记者马...
热血英豪灵异少女带幻影水晶 热血英豪灵异少女带幻影水晶我看见有人用灵异带幻影能幻影出灵异的ZXC,怎么弄的? 是不是他改了...
潍柴:自主锻造“国产引擎” 加... 历时10年,投入1.2亿元,接连突破甲醇发动机抗机油乳化技术、低温冷启动技术、控早燃爆震技术等多项行...
西班牙多地将出现强降雨等极端天... 来源:央视新闻客户端当地时间7月10日,西班牙国家气象局警告称,当地时间11日起,该国多个地区将出现...
来中国前,黄仁勋先去见了特朗普   炒股就看金麒麟分析师研报,权威,专业,及时,全面,助您挖掘潜力主题机会! 【文/观察者网 柳...
警惕虚假宣传诱导网络贷款的风险 转自:中国银行保险报网□本报记者 仇兆燕7月10日,金融监管总局金融消费者权益保护局发布风险提示,提...
比特币突破11.7万美元 续创... .ct_hqimg {margin: 10px 0;} .hqimg_wrapper {text-a...
翼年代记漫画最近章节都说什么了... 翼年代记漫画最近章节都说什么了?OVA《东京默示录》是漫画107话到135话的内容,漫画要从136话...
中国天瑞水泥遭Yu Kuo C... .ct_hqimg {margin: 10px 0;} .hqimg_wrapper {text-a...