admin 管理员组

文章数量: 1184232


2024年3月22日发(作者:eclipse怎么使用教程)

2020年JAVASE综合考试试题库188题[含答案]

一、选择题

1.以下哪些集合接口支持重复元素存在?

答案:B

tion

2."以下代码的输出结果是什么?选择所有的正确答案。

class Example {

public static void main(String[] args) throws IOException {

for (int i = 0; i < 10; i++) {

try {

try {

if (i % 3 == 0)

throw new Exception(""E0"");

n(i);break;

} catch (Exception inner) {

i *= 2;

if (i % 3 == 0)

throw new Exception(""E1"");

} finally {

++i;

}

} catch (Exception outer) {

i += 3;

} finally {

--i;

}

}

}

}"

答案:

A.4

B.5

C.6

D.7

3.Java语言中异常的分类是哪项?

答案:

A.运行时异常和异常

B.受检异常和非受检异常

C.错误和异常

D.错误和运行时异常

4.以下哪个方法是Math类中定义的?

答案:

te()

()

()

()

5.定义在Math类上的round(double d)方法的返回值类型是什么?

答案:

6.以下哪个方法用于计算平方根?

答案:B

Root()

()

()

()

7.调用()方法最有可能输出以下哪些结果?

答案:D

A.-0.12和0.56E3

B.0.12和1.1E1

C.-23.45和0.0

D.0.356和0.03

8."以下代码的输出结果是什么?

public class Example {

public static void main(String[] args) {

n((_VALUE));

}

}"

答案:B

A.输出_VALUE

B.输出一个最接近_VALUE的整数

C.编译失败

D.运行时输出异常信息

9."以下代码的运行结果是什么?

public class Example {

public static void main(String[] args) {

n((0.0, -0.0));

}

}"

答案:C

A.代码编译失败

B.输出0.0

C.输出-0.0

D.代码编译成功,但运行时输出异常信息

10."给出以下代码,为了结果输出-12.0,方法method(d)应为以下哪个方法?

public class Example {

public static void main(String[] args) {

double d = -11.1;

double d1 = method(d);

n(d1);

}

}"

答案: A

()

()

()

()

11.以下哪些类提供了创建一个目录的方法?

答案:A

tput

ory

scriptor

12.以下哪些有关Vector类的描述是正确的?

答案:C

A.该类是个public类

B.该类是个final类

C.该类实现了List接口

D.该类可以序列化

13."以下代码执行结果是什么?

class Example {

public static String output = """";

public static void foo(int i) {

try {

if (i == 1) {

throw new Exception();

}

output += ""1"";

} catch (Exception e) {

output += ""2"";

return;

} finally {

output += ""3"";

}

output += ""4"";

}

public static void main(String[] args) throws IOException {

foo(0);

foo(1);

n(output);

}

}"

答案:

A.无内容输出

B.代码编译失败

C.输出13423

D.输出14323

14.表示键值对概念的接口是哪项?

答案:D

tion

15.List接口的特点是哪项?

答案:C

A.不允许重复元素,元素有顺序

B.允许重复元素,元素无顺序

C.允许重复元素,元素有顺序

D.不允许重复元素,元素无顺序

16.欲构造ArrayList类继承了List接口,下列哪个方法是正确的?

答案:B

ist myList=new Object()

B. List myList=new ArrayList()

ist myList=new List()

myList=new List()

17."下列代码执行后的输出是哪项?

public class Example {

public static void main(String[] args) {

List al = new ArrayList();

(""1"");

(""2"");

(""2"");

(""3"");

n(al);

}

}"

答案:

A.[1,2,3]

B.[1,2,3,3]

C.[1,2,2,3]

D.[2,1,3,2]

18."现有:

list是一个合法的集合引用

getCollection()返回一个合法集合的引用,以下语句哪些是合法的?"

答案:C

(Object o : list)

(Object o : getCollection())

(Object o : or())

(Iterator I;or();t())

19."以下代码的执行结果是?

public class Example {

public static void main(String[] args) {

TreeSet t = new TreeSet();

if ((""one""))

if ((""two""))

if ((""three""))

(""four"");

for (String s : t) {

(s);

}

}

}"

答案:D

eetwo

threefour

ethreetwo

20."现有:

public class Example {

public static void main(String[] args) {

TreeSet s = new TreeSet();

(""one"");

(""two"");

// 插入代码处

for (String s2 : sorted) {

(s2 + "" "");

}

}

}

和四个代码片段:

s1:SortedSet sorted = t(());

s2:SortedSet sorted = t(());

s3:SortedSet sorted = (SortedSet)t(());

s4:SortedSet sorted = (SortSet)t(());

分别插入到插入代码处,哪项可以编译?

"

答案:

A.S2

B.S2和S3

C.S2和S4

D.S2、S3和S4

21.以下哪些语句用于创建一个Map实例?

答案: D

m = new Map();

m = new Map(init capacity,increment capacity);

m = new Map(new Collection());

D.以上都不对

22."下列代码执行后的结果是?

public class Example {

public static void main(String[] args) {

try {

n( == );

n(VE_INFINITY==VE_INFINITY);

} catch (Exception e) {

n(""Exception"");

}

}"

答案:D

A.输出+G20:J20false false

B.输出Exception

C.输出true true

D.输出false true

23.下列哪些项是泛型的优点?

答案:A

A.不用向下强制类型转换

B.代码容易编写

C.类型安全

D.运行速度快

24."下列代码的执行结果是?

class Example {

public static void main(String[] args) throws IOException {

int i = 1, j = 1;

try {

i++;

j--;

if (i == j) {

j++;

}

} catch (ArithmeticException e) {

n(0);

} catch (ArrayIndexOutOfBoundsException e) {

n(1);

} catch (Exception e) {

n(2);

} finally {

n(3);

}

n(4);

}

}"

答案:CD

A.输出1

B.输出2

C.输出3

D.输出4

25.以下哪些方法在Class类中定义?

答案:

structors()

vateMethods()

laredFields()

orts()

26.请问以下哪个程序代码体现了对象之间的is a关系?

答案:

A."public interface Color {

}

public class Shape {

private Color color;

}"

B."public interface Component {

}

public class Cpmtaomer implements Component {

private Component[] children;

}"

C."public class Species{

}

public class Animal{

private Species species;

}"

D."public class Animal{

public interface Species{

}

private Species species;

}"

27."给出以下代码,改程序的执行结果是?

interface Base {

int k = 0;

}

public class Example implements Base {

public static void main(String[] args) {

int i;

Example exm = new Example();

i = exm.k;

i = Example.k;

i = Base.k;

n(i);

}

}"

答案:D

A.无内容输出

B.代码编译失败

C.代码运行时输出异常信息

D.打印输出0

28.Java语言中异常的分类是哪项?

答案:C

A.运行时异常和异常

B.受检异常和非受检异常

C.错误和异常

D.错误和运行时异常

29."现有代码:

public class Example {

public static void main(String[] args) {

try {

(nt(""forty""));

} catch (RuntimeException e) {

n(""Runtime"");

}catch (NumberFormatException e) {

n(""Number"");

}

}

}

执行结果是什么?"

答案:C

A.输出Number

B.输出Runtime

C.输出40

D.编译失败

30."对以下两个代码片段说法正确的是?

代码片段1:

int a = 3;

int b = 0;

int c = a / b;

代码片段2:

float a = 3.0f;

float b = 0.0f;

float c = a / b;"

答案:C

A.执行两端代码都会抛出异常

B.执行两段代码都无异常抛出

C.执行两段代码,只有代码片段1抛出异常

D.执行两段代码,只有代码片段2抛出异常

31."下列代码执行后的结果是?

public class Example {

public static void main(String[] args) {

try {

double x = 64.0;

double y = 0.0;

n(x % y);

} catch (Exception e) {

n(""Exception"");

}

}

}"

答案:D

A.编译失败

B.输出Exception

C.输出Infinity

D.输出NaN

32.关于异常处理,说法错误的是?

答案:C

…catch…finally结构中,必须有try语句块,catch语句块和finally语句块不是必须

的,但至少要两者取其一

B.在异常处理中,若try中的代码可能产生多种异常则可以对应多个catch语句,若catch

中的参数类型有父类子类关系,此时应该将子类放在后面,父类放在前面

C.一个方法可以抛出多个异常,方法的返回值也能够是异常

ble是所有异常的超类

33."关于以下代码,说法正确的是?

class Example {

public static void main(String[] args) throws IOException {

n(""Before Try"");

try {

} catch (Throwable e) {

n(""Inside Catch"");

}

n(""At the End"");

}

}"

答案:B

A.代码编译失败,因为无异常抛出

B.代码编译失败,因为未导入IOException异常类

C."输出Before Try

At the End"

D."输出Inside Catch

At the End"

34."下列代码的执行结果是?

class Example {

private void method1() throws Exception {

throw new RuntimeException();

}

public void method2() {

try {

method1();

} catch (RuntimeException e) {

n(""Caught Runtime Exception"");

} catch (Exception e) {

n(""Caught Exception"");

}

}

public static void main(String[] args) throws IOException {

Example a = new Example();

2();

}

}"

答案:

A.代码编译失败

B.输出Caught Runtime Exception

C.输出Caught Exception

D.输出Caught Runtime Exception和Caught Exception

35."现有如下代码:

public class Example {

public static void main(String[] args) {

try {

int x=nt(""42a"");

//插入代码处

n(""oops"");

}

}

}

在插入代码处插入哪些语句可以在运行后输出oops?"

答案:C

A. } catch (IllegalArgumentException e) { (非法参数异常)

B.} catch (IllegalStateException c) {

C. } catch (NumbelFormatException n) {

D.} catch (ClassCastException c) {

36."现有如下代码:

public class Example {

public static void main(String[] args) {

try {

n(""before"");

doRisyThing();

n(""after"");

} catch (Exception e) {

n(""catch"");

}

n(""done"");

}

public static void doRisyThing() throws Exception{

//this code returns unless it throws an Exception

}

}

该代码可能的执行结果有哪些?"

答案:

catch

after done

catch done

after catch

37.以下哪些描述是正确的?

答案:CD

语句块后必须至少存在一个catch语句块

语句块后可以存在不限数量的finally语句块

语句块后必须至少存在一个catch语句块或finally语句块

D.如果catch和finally语句块同时存在,则catch语句块必须位于finally语句块前

38."请问以下代码的直接执行结果是?

class Example{

public static void main(String[] args) {

try {

n(args[0]);

n(""I'm nomal"");

if (true)

return;

} catch (Exception ex) {

n(""I'm exception"");

if (true)

return;

} finally {

n(""I'm finally."");

}

n(""Out of try."");

}

}"

答案:A

A."I'm exception

I'm finally.

"

B.代码不能编译通过,因为最后一条语句位于return后,不可到达

C.代码编译通过,但运行时输出异常信息

D."I'm nomal

I'm finally."

39."下列代码的运行结果是?

class Example {

public static void main(String[] args) throws IOException {

try {

return;

} finally{

n(""Finally"");

}

}

}"

答案:B

A.无内容输出

B.输出Finally

C.代码编译失败

D.输出异常信息

40.假设有自定义异常类ServiceException,那么抛出该异常的语句正确的是哪项?

答案:C

ServiceException

new ServiceException()

ServiceException

ServiceException

41."现有代码如下:

public class Example {

void topGo() {

try {

middleGo();

} catch (Exception e) {

n(""catch"");

}

}

void middleGo() throws Exception {

go();

n(""late middle"");

}

void go() throws Exception {

throw new Exception();

}

public static void main(String[] args) {

Example example = new Example();

();

}

}

该代码的执行结果是?"

答案:B

A.输出late middle

B.输出catch

C.输出late middle catch

D.输出catch late middle

42.请问以下哪些关于try…catch…finally结构中的finally语句的描述是正确的?

答案:C

A.只有当一个catch语句获得执行后,finally语句才获得执行

B.只有当catch语句未获得执行时,finally语句才获得执行

C.如果有finally语句,return语句将在finally语句执行完毕后才会返回

D.只有当异常抛出时,finally语句才获得执行

43."关于以下代码,说法正确的是?

class Example{

public static void main(String[] args) throws IOException {

if (args[0] == ""hello"") {

throw new IOException();

}

}

}"

答案:A

A.代码编译成功

B.代码编译失败,因为main()方法是入口方法,不能抛出异常

C.代码编译失败,因为IOException异常是系统异常,不能由应用程序抛出

D.代码编译失败,因为字符串应该用equals方法判定一致性

44."关于以下代码,说法正确的是?

class Example {

public static void main(String[] args) throws IOException {

n(""Before Try"");

try {

} catch (ption e) {

n(""Inside Catch"");

}

n(""At the End"");

}

}"

答案:

A.代码编译失败,因为无异常抛出

B.代码编译失败,因为未导入IOException异常类

C."输出Before Try

At the End"

D."输出Inside Catch

At the End"

45."给出以下代码:

class Example {

public static void main(String[] args) throws IOException {

try {

methodA();

} catch (IOException e) {

n(""caught IOException"");

}catch (Exception e) {

n(""caught Exception"");

}

}

}

如果methodA()方法抛出一个IOException异常,则该程序的运行结果是什么?"

答案:

A.无内容输出

B.代码编译失败

C.输出caught IOException

D.输出caught Exception

46."以下代码的执行结果是?

public class Example {

public static void main(String[] args) {

File f = new File(""c:"");

}

}"

答案:

文件在本地硬盘上被创建

B.在Unix系统上运行失败,因为路径分割符不正确

文件在本地硬盘上没有被创建

D.如果文件已经存在,则一个异常被抛出

47."当fragile()方法抛出一个IllegalArgumentException异常时,下列代码的运行结果是什

么?

public static void main(String[] args) throws IOException {

try {

fragile();

} catch (NullPointerException e) {

n(""NullPointerException thrown"");

} catch (Exception e) {

n(""Exception thrown"");

} finally {

n(""Done with exceptions"");

}

n(""myMethod is done"");

}

}"

答案:

A.输出NullPointerException thrown

B.输出Exception thrown

C.输出Done with Exception

D.输出myMethod is done

48."以下代码执行的结果是:

public class Example {

public static void main(String[] args) {

int[] x = { 1, 2, 3 };

x[1] = (x[1] > 1) ? x[2] : 0;

n(x[1]);

}

}"

答案:C

A.输出1

B.输出2

C.输出3

D.输出4

49.数组是什么类型?

答案:A

A.引用类型

B.基本数据类型

C.不能确定

D.其他类型

50.数组中可以存什么类型的数据?

答案:C

A.只能存基本数据类型

B.只能存引用类型

C.都可以

D.都不可以

51.下面哪条语句不正确?

答案:A

[4] a;

a[];

[] a;

[] a,b;

52.下面哪条语句不正确?

答案:C

[] a={1,2,3};

a[]=new int[4];

[] a=new int[];

[] a=new int[]{2,3,4};

53.存在Employee类,如何创建一个长度为3的Employee类型数组?

答案:B

ee[3] e;

ee[] e=new Employee[3];

ee e[3];

ee[3] e=new Employee[];

54.以下哪些是声明一个字符串数组的正确形式?

答案:ABD

[] s;

[]s;

[s]

s[]

55.以下哪些是初始化数组的正确形式?

答案:ABD

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

[]x[] = {{1,2,3},{1,2,3}};

x[3] = {1,2,3};

[]x = {0,0,0};

56.假设存在int型数组a,哪项是正确的增强for循环迭代该数组?

答案:C

(int[] a){}

(int a){}

(int x:a){}

(int i>0;i<;i++){}

57."以下代码运行输出的结果是什么?

public class Example {

public static void main(String[] args) {

char[] c = new char[100];

n(c[50]);

}

}"

答案:D

A.打印输出50

B.打印输出49

C.打印输出u0000

D.打印输出null

58."以下代码执行结果是?

public class Example {

public static void main(String[] args) {

TreeMap map = new TreeMap();

(""one"", ""1"");

(""two"", ""2"");

(""three"", ""3"");

displayMap(map);

}

static void displayMap(TreeMap map) {

Collection c = et();

Iterator i = or();

while (t()) {

Object o = ();

(ng());

}

}

}"

答案:

three

B.123

=1three=3two=2

eetwo

59."给出下面代码:

public class Example{

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

public static void main(String a[])

{

n(arr[1]);

}

}

那个语句是正确的?"

答案:D

A.编译时将产生错误

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

C.输出0

D.输出null

60.下面哪个是包装器类型?

答案:A

r

61.从InputStream对象中如何创建一个Reader对象?

答案:

A.使用InputStream类中定义的createReader()方法

B.吃用Reader类中的createReader()方法

C.构造一个InputStreamReader实例,将InputStream对象作为InputStreamReader类构造器

的参数传入

D.构造一个OutputStreamReader实例,将InputStream对象作为OutputStreamReader类构造

器 的参数传入

62.以下哪个描述是正确的?

答案:

A.多线程是Java语言独有的

B.多线程需要多CPU

C.多线程要求一个计算机拥有单独一个CPU

语言支持多线程

63.以下哪个是Runnable接口中定义的方法?

答案:

()

()

()

()

64."以下代码的执行结果是?

public class Example implements Runnable {

public static void main(String args[]) {

Example ex = new Example();

Thread t = new Thread(ex);

();

}

void run() {

(""pong"");

}

}"

答案:

A.输出pong

B.运行时输出异常信息

C.运行后无任何输出

D.编译失败

65."现有:t是一个合法的Thread对象的引用,并且t的合法run()方法如下:

public void run() {

(""go"");

}

执行:

();

();

();

后结果是什么?"

答案:

go

go go

之后跟着一个异常

go之后跟着一个异常

66."下列代码的执行结果是?

public class Example{

public static void main(String args[]) {

Thread t = new Thread() {

public void run() {

pong();

}

};

();

(""ping"");

}

static void pong() {

(""pong"");

}

}"

答案:

ng

ng

ng和pongping都有可能

D.都不输出

67.以下哪个关于Runnable的描述是正确的?

答案:

le是Java语言的一个关键字,用于修饰类,来表明该类是一个独立线程

le是一个接口,实现该接口的类对象可以提供给Thread类构造器作为创建线程的

依据

le是一个类,继承该类的子类可以作为独立的线程存在

D.以上皆不对

68.Java UDP编程主要用到的两个类型是

答案:

ket

amSocket

ket

amPacket

69.为了保证方法的线程安全,声明方法的时候必须使用哪个修饰符?

答案:

ent

onized

70."下列代码的执行结果是什么?

public class Example {

public static void main(String[] args) {

int index = 1;

int[] foo = new int[3];

int bar = foo[index];

int baz = bar + index;

n(baz);

}

}"

答案:B

A.打印输出0

B.打印输出1

C.打印输出2

D.运行期间有异常抛出

71.以下哪个是10进制数123的正确的十六进制表示?

答案:

A.0x67

B.0x123

C.0x7B

D.67

72."现有:

f是一个File类实例的合法引用

fr是一个FileReader类实例的合法引用

br是一个BufferedReader类实例的合法引用

如下代码:

String line = null;

//插入代码处

n(line);

哪一行代码插入到插入代码处将循环一次输出文本文件的一行?"

答案:

((line = ())!=null){

((line = ())!=null){

((line = ())!=null){

((line = ne())!=null){

73."现有:

String s = ""write a line to a file"";

(s + ""n"");

哪一个是对的?"

答案:

A.w既可以是PrintWriter类型,也可以是BufferedWriter类型

B.w既不可以是PrintWriter类型,也不可以是BufferedWriter类型

C.w可以是PrintWriter类型,但不可以是BufferedWriter类型

D.w既可以是BufferedWriter类型,也可以是PrintWriter类型

74.以下哪些是FileOutputSteram类的正确构造形式?

答案:

tputStream(FileDescriptor fd)

tputStream(String n,boolean a)

tputStream(boolean a)

tputStream(File f)

75.以下哪些描述是正确的?

答案:

tream和OutputStream类是基于字节流的

InputStream类和ObjectOutputStream类不支持序列化的对象

和Writer是基于字符流的

类和Writer类是支持对象序列化的首选

76.以下哪些描述是正确的?

答案:

类可以使用不同的字符编码向输出流写入字符

类可以向输出流写入Unicode字符

类提供向输出流写入任意Java基本数据类型的方法

类提供向输出流写入引用数据类型的方法

77.属性可以使用哪个访问权限修饰符?

答案:C

ted

e

D.都可以

78.构造方法可以使用哪个访问权限修饰符?

答案:A

ted

e

D.都可以

79.如果类中的成员变量只可以被同一包访问,则使用如下哪个约束符?

答案:C

A. private

ted

modifier

80.为了能够访问对封装的属性的访问和修改,方法往往用哪个修饰符修饰?

答案:A

ted

e

D.都可以

81."下列代码在JDK1.5以上版本执行的结果是?

public class Example {

public static void main(String[] args) {

Integer i = 10;

Integer j = 10;

n(i == j);

i = 210;

j = 210;

n(i == j); (超过-128~127为false)

}

}"

答案:B

A.抛出异常

B.输出true false

C.输出true true

D.输出false false

82."执行下列语句后,变量i的值是:

byte i = 127; byte(-2^7 ~ 2^7-1)

i += 1; (当溢出时回到最小)"

答案:D

A.128

B.0

C.-1

D.-128

83.Java语言中有多少个包装器类型?

答案:B

A.7

B.8

C.9

D.无数个

84.下面哪个赋值语句是合法的?

答案:C

a = 2.0

b = 2.0

c = 2

d = 2

85.下面哪个类型是引用类型?

答案:A

ee

86.下面哪个不是引用类型?

答案:D

87.下面哪个说法正确?

答案:A

A.基本数据类型都可以直接使用=赋值

B.引用类型绝对不能直接用=赋值,都需要使用new关键字

不是引用类型

是引用类型

88.0.5和0.5f的以下说法正确的式?

答案:B

A.都是引用类型

是引用类型,double是基本数据类型

C.都是基本数据类型

是基本数据类型,double是引用类型

89."Student s1=new Student(""John"");

Student s2=new Student(""Alice"");

s1=s2;

n(e());

输出结果为?"

答案:D

D.不能确定

90."public class TestChange {

/**

*

* @param str

*/

public static void changeStr(String str){

str=“"";

}

public static void main(String[] args){


本文标签: 代码 方法 语句 输出 结果