JAVA复习11111

  • 格式:doc
  • 大小:61.00 KB
  • 文档页数:7

一:选择题

1.欲构造ArrayList类的一个实例,此类继承了List接口,下列哪个方法是正确的?B

A ArrayList myList=new Object();

B List myList=new ArrayList();

C ArrayList myList=new List();

D List myList=new List();

2.以下Java语句中,String str = “123456789”;str =str.subString(1,3);执行后str中的值为。A

A. “23”

B. “123”

C. “12”

D. “234”

3.paint()方法使用哪种类型的参数?A

A Graphics

B Graphics2D

C String

D Color

4.给定如下java代码,以下(D)代码行编译会报错。

class MyClass{

void myMethod(final int p){

final int il;

final int i2=p;

i1=20;

i2=20;

}

}

A.void my Method(final int p)

B.final int il;

C.final int i2=p

D.i2=20;

5.指出正确的表达式 C

A byte=128;

B Boolean=null;

C long l=0xfffL;

D double=0.9239d;

6.指出下列程序运行的结果 B

public class Example{

String str=new String("good");

char[]ch={'a','b','c'};

public static void main(String args[]){

Example ex=new Example();

ex.change(ex.str,ex.ch);

System.out.print(ex.str+" and ");

Sytem.out.print(ex.ch);

}

public void change(String str,char ch[]){

str="test ok";

ch[0]='g';

}

}

A good and abc

B good and gbc

C test ok and abc

D test ok and gbc

6.在java中,()对象可以使用键/值的形式保存数据。

a)ArrayList

b) HashSet

c) HashMap

d) LinkedList

7.运行下列程序, 会产生什么结果 A

public class X extends Thread implements Runable{

public void run(){

System.out.println("this is run()");

}

public static void main(String args[])

{

Thread t=new Thread(new X());

t.start();

}

}

A 第一行会产生编译错误

B 第六行会产生编译错误

C 第六行会产生运行错误

D 程序会运行和启动

8.给定java代码如下,运行时,会产生(A)类型的异常。

String s=null;

s.concat(“abc”);

a)ArithmeticException

b)NullPointerException

c)IOException

d)EOFException

9.要从文件" file.dat"文件中读出第10个字节到变量C中,下列哪个方法适合?

A FileInputStream in=new FileInputStream("file.dat"); in.skip(9); int c=in.read();

B FileInputStream in=new FileInputStream("file.dat"); in.skip(10); int c=in.read();

C FileInputStream in=new FileInputStream("file.dat"); int c=in.read();

D RandomAccessFile in=new RandomAccessFile("file.dat"); in.skip(9); int c=in.readByte();

10.容器被重新设置大小后,哪种布局管理器的容器中的组件大小不随容器大小的变化而改变?

A CardLayout

B FlowLayout

C BorderLayout

D GridLayout

11.在Java中,在包com.db下定义一个类,要让包com.util下的所有类都可以访问这个类,这个类必须定义为(C)。

a)protected

b)private

c)public

d)friendly

12.在Java中,下列(D)语句不能通过编译。 (选择一项)

a) String s= “join”+ “was”+ “here”;

b) String s= “join”+3;

c) int a= 3+5

d) float f=5+5.5;

13.给出下面代码: C

public class Person{

static int arr[] = new int[10];

public static void main(String a[])

{

System.out.println(arr[1]);

}

}

那个语句是正确的?

A 编译时将产生错误;

B 编译时正确,运行时将产生错误;

C 输出零;

D 输出空。

14.给定java代码,如下:B

public byte count(byte b1,byte b2){

return______;

}

要使用这段代码能够编译成功,横线处可以填入(A) 。

a) (byte) (b1-b2)

b) (byte) b1-b2

c) b1-b2

d) (byte) b1/b2

15.哪个关键字可以对对象加互斥锁?B

A transient

B synchronized

C serialize

D static

16.下列哪些语句关于内存回收的说明是正确的? C

A 程序员必须创建一个线程来释放内存;

B 内存回收程序负责释放无用内存

C 内存回收程序允许程序员直接释放内存

D 内存回收程序可以在指定的时间释放内存对象

18.java程序中,main方法的格式正确的是()。

a)static void main(String[] args)

b)public void main(String[] args)

c)public static void main(String[]s)

d)public static void main(String[] args)

19.在Java中下列()方法可以把JFrame的布局管理器设为FlowLayout类型A

a)jFrame.setLayout(new FlowLayout() );

b) jFrame.addLayout(new FlowLayout() )

c)jFrame.setFlowLayout()

d)jFrame.addFlowLayout()

20.给定如下java代码,编译运行之后,将会输出(D)。

public class Test{

public staticvoid main(String args[]){

int a=5;

System.out.println(a%2==1) ?(a+1) /2:a/2) ;

}

} (选择一项)

a)1

b)2

c)2.5

d)3

21.在java中,在尝试对null 对象操作时,不会产生( B)类型的异常。

a) ArithmeticException

b) NullPointerException

c) IOException

d) EOFException

22.Java语言中,String str=”123456789”,System.out.println(str.indexOf(“5”)),输出结果不会是(ABD)。

a) 6

b) 5

c) 4

d) -1

23.执行下列代码后,哪个结论是正确的 String[] s=new String[10]; BD

A s[10] 为 "";

B s[9] 为 null;

C s[0] 为 未定义

D s.length 为10

24.选出合理的标识符 AC

A _sys1_lll

B 2mail