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

相关内容

热门资讯

缅北白家致中国公民6人死亡 【#缅北白家致中国公民6人死亡#】#缅北白家涉赌资金超180亿元#公安部部署开展打击缅北涉我犯罪专项...
2025年GEO排名优化公司榜... 数字化浪潮席卷全球的当下,AI搜索已然成为企业提升品牌影响力、抢占市场先机的战略要地。当用户在Dee...
大项目、大订单陆续交付 博隆技... 7月11日,博隆技术发布业绩预告。经公司财务部初步测算,2025年上半年,公司预计实现归属于母公司所...
如何理解特定股票代码开头的含义... 在股票投资领域,理解特定股票代码开头的含义至关重要,它不仅是识别股票的关键标识,还能为股票分析提供有...
东方财富成交额逾百亿! 格隆汇7月11日|东方财富涨超4%,成交额逾100亿元。
港股异动丨药明康德业绩亮眼,刺... 格隆汇7月11日|港股市场CRO概念股集体走强,其中,凯莱英涨超15%,药明康德涨12%,昭衍新药、...
【光明论坛】奋力书写挺膺担当的... 来源:国际在线近日,中华全国青年联合会第十四届委员会全体会议、中华全国学生联合会第二十八次代表大会在...
盛天网络投资成立互娱科技公司 人民财讯7月11日电,企查查APP显示,近日,武汉市带带互娱科技有限公司成立,法定代表人为杨影,注册...
金融科技板块活跃 安硕信息涨幅...   07月11日消息,截止10:45,金融科技板块活跃,瑞达期货涨停,安硕信息、恒宝股份(维权)、国...
石文先委员:构建符合时代要求的... 转自:人民政协报企业是国家经济核心构成和根本支撑。日前,中共中央办公厅、国务院办公厅发布了《关于完善...