您的当前位置:首页JavaSE试题

JavaSE试题

来源:小侦探旅游网


JavaSE笔试题

(本卷总分100分,60分及格,时间120分钟)

一,选择题(每小题2分,共20题,总计40分)

1. 下面哪些是合法的标识符?( abe)

A. $persons B. TwoUsers C. *point D. this E. _endline

2. 下面程序运行的结果是( a) class Example{

public static void main(String[] args){ int i = 45678;

int j = ~i;

System.out.println(j);

} }

A.编译错误 B.输出45677 C.输出-45677 D.输出 -45679

3.下面程序运行的结果是( d ) public class Example{

public static void main(String[] args){ int i = 100; switch(i){ case 100:

System.out.print(i); case 200: System.out.print(i); case 300: System.out.print(i); } } }

A.无任何输出 B.编译错误 C.输出100100100 D.输出100

4. 哪些不是Java关键字? ( a b )

A. TRUE B. sizeof C. const D. super E. void

5.下面程序运行的结果是( c ) class Example{

public static void main(String[] args){ int x;

double y = -10.9; x=(int)y;

1

System.out.print(x + “”); y = 10.9; x = (int)y;

System.out.println(x); } }

A.-11 10 B.-11 11 C.-10 10 D.-10 11

6.下面哪个方法可以通知Java虚拟机调用垃圾回收器来回收已废弃对象? ( a ) A.System.gc() B.Runtime.gc() C.System.freeMemory D.Runtime.getRuntime().growHeap()

7. 下面程序运行的结果是( b) public class Example{ int x = 12;

public void method(int x){ x += x;

System.out.println(x); }

public static void mian(String[] args){ Example t = new Example(); t.method(5); } }

A.5 B.10 C.12 D.17 E.24

8. 下面程序运行的结果是(c ) class Base{

private void amethod(int iBase){ System.out.println(“Base.amethod”); } }

class Example extends Base{ public static void main(String[] args){ Example o = new Example(); int iBase = 0; o.amethod(iBase); }

public void amethod(int iover){

System.out.println(“Example.amethod”); } }

A.编译错误 B.运行错误 C.输出Base.amethod D.输出Example.amethod

2

9. 下面程序运行的结果是( c ) Class Example1{

public Example1(){

System.out.print(1); } }

class Example2 extends Example1{ public Example2(){

System.out.print(2); } }

class Example3 extends Example2{ public Example3(){

System.out.print(3); } }

public class Example{

public static void main(String[] args){ new Example3(); } }

A.1 B.3 C.123 D.321

10. 下面程序运行的结果是( a ) public class Example{ class Inner{ void test(){ sample(); } }

private Boolean flag = false; public void sample(){ System.out.println(“Sample”); } public Example() { (new Inner()).test(); }

public static void main(String[] args){ new Example(); } }

A.输出Sample B.输出null C.编译错误

11.下面哪一个方法是属于Math类的?(b )

3

D.运行错误

A.absolute() B.log() C.cosine() D.sine()

12. 下面程序运行的结果是( b ) Public class Example{

public static void main(String[] args) { Integer ten = new Integer(10); Long nine = new Long(9);

System.out.println(ten + nine); int i =1;

System.out.println(i + ten); } }

A.19 20 B.19 11 C.运行错误 D.11 1

13. 在下列选项中,t变量的值为( d ) String s = “hypertext”; String t = s.substring(2,5);

A. “yper” B.“ype” C. “pert” D. “per”

14.下面代码运行的结果为( d ) class Example{

public static void main(String[] args){ String str = “Welcome”; str.concat(“to Java!”); System.out.println(str); } }

A.编译错误 B.运行异常 C.Prints “Welcome” D.Prints “Welcome to Java! ”

15.下列代码运行的结果为( a ) class Example{ public static void main(String[] args){ Vector a = new Vector(); a.addElement(10); System.out.println(a.elementAt(0)); } }

A.Prints 10 B.Prints 11 C.编译错误 D.运行异常

16.下列代码运行的结果为( a ) public class Example{

public static void main(String[] args){ Integer i = 10; Integer j = 10;

4

System.out.print(i==j);

System.out.print(i.equals(j)); } }

A.false false B.true true C.true false D.false true

17. 下列代码在C:\\source目录下运行,结果为( c ) import java.io.*; class Example{

public static void main(String[] args){ File file = new File(“Ran.test”);

System.out.println(file.getAbsolutePath());

} }

A.Ran.test

B.source\\Ran.test C.c:\\source\\Ran.test D. c:\\source

18.下列代码运行的结果为( d )

public class Example implements Runnable { public void run() {

System.out.print(“running ”); }

public static void main(String[] args){ Thread t = new Thread(new Example()); t.run(); t.run(); t.start(); } }

A.编译错误 B.运行异常 C.running running D.running running running

19.下列代码运行的结果为( c ) public class Example extends Thread{ public void run() { System.out.print (“Before start method ”); this.stop();

System.out.println(“After stop method”); }

public static void main(String[] args){ Example a = new Example(); a.start(); }

5

}

A.编译错误 B.运行异常

C.Before start method After stop method D. Before start method

20.下列代码运行的结果为( a) class Example{

public static void main(String[] args){ divide(4,0); }

public static void divide(int a,int b){ try{

int c=a/b; }

Catch(Exception e) { System.out.print(“Exception ”);} Finally{ System.out.println(“Finally”);} } }

A.Exception Finally B.Finally C.Exception D.无输出

二,问答题(每小题6分,共10题,总计60分)

1. 面向对象的特征有哪些方面?并简述每一个特征。 继承,封装,多态;

2. Java的基本数据类型有哪些?并写出他们的取值范围。 Int,double,float;boolen,type,

3. 什么是GC?为什么要有GC?Java是如何实现GC的? 垃圾处理器

4. 简述java中的访问修饰符及其访问范围。

看String类型的对象改变了值,但事实是他不能改变值,只能改变指向的地址

StringBuffer则不同,直接改变指向的地址中保留的值

5. String 和StringBuffer的区别。

6. 举例阐述单例模式。

7. 请写出你所知道的线程同步的方法。 8. 简述JAVA中的Collection框架。

9. 简述TCP/IP的工作原理。

10. 编程题 a.字符串\"yekmaakkccekymbvb\求字符串中有多少种字符以及每个字符的个数

6

b.把结果写入D盘名为test的文本文件中。 c.读出刚才写入test文本文件的内容。

选作题:

11. 启动3个线程打印递增的数字, 线程1先打印1,2,3,4,5, 然后是线程2打印6,7,8,9,10,

然后是线程3打印11,12,13,14,15. 接着再由线程1打印16,17,18,19,20....以此类推, 直到打印到75. 程序的输出结果应该为: 线程1: 1 线程1: 2 线程1: 3 线程1: 4 线程1: 5 线程2: 6 线程2: 7 线程2: 8 线程2: 9 线程2: 10 ...

线程3: 71 线程3: 72 线程3: 73 线程3: 74 线程3: 75

7

因篇幅问题不能全部显示,请点此查看更多更全内容