附录A综合复习题newWord下载.docx

上传人:b****3 文档编号:16352146 上传时间:2022-11-23 格式:DOCX 页数:25 大小:25.54KB
下载 相关 举报
附录A综合复习题newWord下载.docx_第1页
第1页 / 共25页
附录A综合复习题newWord下载.docx_第2页
第2页 / 共25页
附录A综合复习题newWord下载.docx_第3页
第3页 / 共25页
附录A综合复习题newWord下载.docx_第4页
第4页 / 共25页
附录A综合复习题newWord下载.docx_第5页
第5页 / 共25页
点击查看更多>>
下载资源
资源描述

附录A综合复习题newWord下载.docx

《附录A综合复习题newWord下载.docx》由会员分享,可在线阅读,更多相关《附录A综合复习题newWord下载.docx(25页珍藏版)》请在冰豆网上搜索。

附录A综合复习题newWord下载.docx

5)publicvoidgo(){

6)ArrayList<

Student>

al=newArrayList<

();

7)getList(al);

8)}

9)//getList方法的定义

10)_______________________________________________

11)_______________________________________________

12)_______________________________________________

13)}

5、在以下程序的横线处填写代码,使得该代码总是输出[10,20]

2)publicclassDemoimplements______________{

3)privateinti;

4)publicDemo(inti){

5)this.i=i;

7)publicstaticvoidmain(String[]args){

8)______________________________________

9)v.add(newDemo(20));

10)v.add(newDemo(10));

11)Collections.sort(v);

12)System.out.println(v);

13)}

14)publicintcompareTo(Objecto){

15)_________________________

16)returnthis.i-d.i;

17)}

18)publicStringtoString(){

19)_________________________

20)}

21)}

6、给定以下的代码:

1)publicclassPerson{

2)privateStringname;

3)publicPerson(Stringname){

4)this.name=name;

5)}

6)publicbooleanequals(Personp){

7)returnp.name.equals(this.name);

9)}

以下哪句描述是正确的?

()

A.该类中的equals方法没有正确重写Object类中的equals方法.

B.因为第5行的私有属性name不能被访问,所以编译错误.

C.为了使基于hash的数据结构能正常工作,该类必须实现hashCode方法.

D.当向一个java.util.Set集合中添加Person类的对象,第四行的equals方法将阻止添加重复元素.

7、给定以下的代码:

22)publicclassPointimplementsComparable<

Point>

{

23)privateintx,y;

24)publicPoint(intx,inty){

25)this.x=x;

26)this.y=y;

27)}

28)publicintgetX(){returnx;

}

29)publicintgetY(){returny;

30)publicStringtoString(){

31)return"

<

"

+x+"

"

+y+"

>

;

32)}

33)_______________________________

34)}

在横线处填写代码使该类能够通过编译?

8、给定以下没有使用泛型的方法:

1)publicstaticintsum(Listlist){

2)intsum=0;

3)for(Iteratoriter=list.iterator();

iter.hasNext();

){

4)inti=((Integer)iter.next()).intValue();

5)sum+=i;

6)}

7)returnsum;

8)}

修改以上代码,使该类使用泛型机制来完成相同功能,又可以避免不安全的警告?

_____________________________________________

9、给定以下代码:

2)publicclassWrappedString{

3)privateStrings;

4)publicWrappedString(Strings){this.s=s;

5)publicstaticvoidmain(String[]args){

6)HashSet<

Object>

hs=newHashSet<

7)WrappedStringws1=newWrappedString("

aardvark"

8)WrappedStringws2=newWrappedString("

9)Strings1=newString("

10)Strings2=newString("

11)hs.add(ws1);

hs.add(ws2);

hs.add(s1);

hs.add(s2);

12)System.out.println(hs.size());

14)}

运行的结果是什么?

A.0

B.1

C.2

D.3

E.4

F.编译失败

G.运行时抛出一个异常.

10、以下哪些不是java.sql包里的类或者接口?

A.Connection

B.PreparedStatement

C.DataSource

D.Statement

E.ResultSet

11、给定一下代码:

2)publicclassSortDemo{

3)publicstaticvoidmain(String[]args){

4)HashMap<

Integer,String>

hm=newHashMap<

5)hm.put(10,"

abc"

6)hm.put(50,"

gdf"

7)hm.put(30,"

fds"

8)Collections.sort(hm);

9)hm.put(20,"

jfd"

10)Collections.reverse(hm);

11)System.out.println(hm);

12)}

13)}

A.{50=gdf,20=jfd,10=abc,30=fds}

B.{10=abc,20=jfd,30=fds,50=gdf}

C.{10=abc,30=fds,50=gdf,20=jfd}

D.编译错误

E.运行时抛出一个异常

12、假设数据库连接成功,conn是一个数据库连接对象,以下哪两段代码是正确查询数据库中一个名叫Student表里的所有数据的代码?

A.Statementstmt=conn.getStatement();

stmt.executeQuery("

Select*fromStudent"

B.PreparedStatementpstmt=conn.prepareStatement("

pstmt.executeQuery();

C.PreparedStatementpstmt=conn.createPrepareStatement("

D.Statementstmt=conn.createStatement();

13、在以下的代码的横线处填写代码,使之可以完成序列化和反序列化的功能:

1)importjava.io.*;

2)publicclassPointimplementsSerializable{

3)publicIntegerx,y;

4)publicPoint(Integerx,Integery){

5)this.x=x;

6)this.y=y;

7)}

8)privatevoidwrite(ObjectOutputStreamoos)throwsException{

9)____________________________

10)____________________________

11)}

12)privatevoidread(ObjectInputStreamois)throwsException{

13)____________________________

14)____________________________

15)}

16)}

14、给定以下代码:

2)classFlowerimplementsSerializable{

3)intprice=5;

4)}

5)classroseextendsFood{

6)intprice=6;

7)}

8)classYellowRoseextendsFruit{

9)intprice=4;

10)}

11)publicclassSerialDemo{

12)publicstaticvoidmain(String[]args){

13)try{

14)YellowRoseyr=newYellowRose();

15)YellowRoseyr2=newYellowRose();

16)FileOutputStreamfos=newFileOutputStream("

file.ser"

17)ObjectOutputStreamoos=newObjectOutputStream(fos);

18)oos.writeObject(yr);

19)FileInputStreamfis=newFileInputStream("

20)ObjectInputStreamois=newObjectInputStream(fis);

21)yr2=(YellowRose)ois.readObject();

22)System.out.println(yr2.price+yr2.price+yr2.price);

23)}catch(Exceptionex){

24)ex.printStackTrace();

25)}

26)}

27)}

结果是什么?

A.15

B.18

C.12

15、给定以下的代码片段:

1)Object[]myObjs={newInteger(30),newString("

10"

),newInteger(20),newBoolean(false)};

2)Arrays.sort(myObjs);

3)for(Objecto:

myObjs){

4)System.out.print(o.toString()+"

"

5)}

A.因为1行的错误导致编译错误

B.因为2行的错误导致编译错误

C.运行时在2行出现一个ClassCastException异常

D.运行时在3行出现一个ClassCastException异常

E.输出:

0102030

16、给定以下的代码:

2)classMyClass{

3)Strings;

4)MyClass(Strings){

5)this.s=s;

8)publicclassDemo{

9)publicstaticvoidmain(String[]args){

10)HashSeths=newHashSet();

11)MyClassmc1=newMyClass("

hello"

12)MyClassmc2=newMyClass("

13)Strings1=newString("

14)Strings2=newString("

15)hs.add(mc1);

16)hs.add(mc2);

17)hs.add(s1);

18)hs.add(s2);

19)System.out.println(hs.size());

21)}

A.0

B.1

C.2

D.3

E.4

17、以下哪三段代码可以通过编译(选三项)()

A.publicvoidmethod(List<

?

extendsString>

list){

list.add("

foo"

}

B.publicvoidmethod(List<

Objecto=list;

C.publicvoidmethod(List<

Strings=list.get(0);

D.publicvoidmethod(List<

list=newArrayList<

String>

E.publicvoidmethod(List<

18、给定以下代码:

2)publicclassHashSetDemo{

4)HashSet<

Integer>

5)Integeri1=newInteger(25);

6)Integeri2=newInteger(26);

7)hs.add(i1);

8)hs.add(i1);

9)hs.add(i2);

10)System.out.print(hs.size()+"

\t"

11)hs.remove(i1);

12)System.out.print(hs.size()+"

13)i2=newInteger(27);

14)hs.remove(i2);

15)System.out.print(hs.size());

16)}

17)}

A.编译错误

B.运行时抛出一个异常

C.210

D.211

E.321

F.322

19、给定以下代码:

2)interfaceA{

3)voidx();

4)}

5)classBimplementsA{

6)publicvoidx(){

8)publicvoidy(){

11)classCextendsB{

12)publicvoidx(){

14)}

15)publicclassLimited{

16)publicstaticvoidmain(String[]args){

17)List<

A>

list=newArrayList<

18)list.add(newB());

19)list.add(newC());

20)for(Aa:

21)a.x();

22)a.y();

23)}

24)}

25)}

A.这段代码运行没有输出

C.第11行导致编译错误

D.第17行导致编译错误

E.第20行导致编译错误

F.第22行导致编译错误

20、给定以下代码:

2)publicclassTreeSetDemo{

4)TreeSet<

ts=newTreeSet<

5)ts.add(30);

6)ts.add(10);

7)ts.add(60);

8)Iteratorit=ts.iterator();

9)while(it.hasNext()){

10)Integern=(Integer)it.next();

11)System.out.print(n+"

12)}

B.运行抛出一个异常

C.103060

D.301060

21、要创建一个泛型类GenericClass,而该泛型类的参数必须实现Comparable接口,下面哪一个GenericClass泛型类的定义可以通过编译?

A.classGenericClass<

TextendsComparable<

T>

Tt;

B.classGenericClass<

TimplementsComparable<

}

C.classGenericClass<

Tt;

D.classGenericClass<

TimplementsComparable<

22、给定以下的代码

4)ArrayList<

str=newArrayList<

5)str.add("

student"

6)str.add("

7)str.add("

world"

8)str.

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 党团工作 > 入党转正申请

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1