JAVASE 部分
1、Choose the three valid identifiers from those listed below. (Choose three)? A. IDoLikeTheLongNameClass
B. $byte
C. const
D. _ok
E. 3_case
答:ABD
2、Which of the following lines of code will compile without error (Choose two)?
A.
int i=0;
if (i) {
System.out.println(“Hi”);
}
B.
boolean b=true;
boolean b2=true;
if(b==b2) {
System.out.println(“So true”);
}
C.
int i=1;
int j=2;
if(i==1|| j==2)
System.out.println(“OK”);
D.
int i=1;
int j=2;
if (i==1 &| j==2)
System.out.println(“OK”);
答:BC
3、Which two demonstrate a "has a" relationship(Choose two)?
A. public interface Person { } public class Employee extends Person{ }
B. public interface Shape { } public interface Rectandle extends Shape { }
C. public interface Colorable { } public class Shape implements Colorable { } D. public class Species{ } public class Animal{private Species species;}
E. interface Component{ } class Container implements Component{ private Component[] children; }
答:DE
4、What will happen when you attempt to compile and run the following code?
public class Static{
static {
int x = 5;
}
static int x,y;
public static void main(String args[]){
x--;
myMethod();
System.out.println(x + y + ++x);
}
public static void myMethod(){
y = x+++++x;
}
}
A.compiletime error
B.prints: 1
C.prints: 2
D.prints: 3
E.prints: 7
F.prints: 8
答:D
5、What is the correct ordering for the import, class and package declarations when found in a single file?
A. package, import, class
B. class, import, package
C. import, package, class
D. package, class, import
答:A
6、What will happen when you attempt to compile and run the following code. public class Pvf{
static boolean Paddy;
public static void main(String argv[]){
System.out.println(Paddy);
}
}
A. Compile time error
B. compilation and output of false
C. compilation and output of true
D. compilation and output of null
答:B
7、Given the folowing classes which of the following will compile without error?
interface IFace{}
class CFace implements IFace{}
class Base{}
public class ObRef extends Base{
public static void main(String argv[]){
ObRef ob = new ObRef();
Base b = new Base();
Object o1 = new Object();
IFace o2 = new CFace();
}
}
A. o1=o2;
B. b=ob;
C. ob=b;
D. o1=b;
答:ABD
8、下面那几个函数是 public void method(){...}的重载函数?
A)public void method( int m){...}
B)public int method(){...}
C)public void method2(){...}
D)public int method(int m,float f ){...}
答:AD
9、给出如下声明: String s = “Example”; 合法的代码有哪些?
A)s>>>=3
B)s[3]= “X”
C)int i = s.length()
D)s = s + 10
答:CD
10、如下哪些不是 java 的关键字?
A)const
B)NULL
C) false
D)this
E) native
答:B
11、关于垃圾收集的哪些叙述是对的
A)程序开发者必须自己创建一个线程进行内存释放的工作
B)垃圾收集将检查并释放不在使用的内存
C)垃圾收集允许程序开发者明确指定并立即释放该内存
D)垃圾收集能够在期望的时间释放被 java 对象使用的内存
答:B
12、已知表达式 int m [ ] = {0,1,2,3,4,5,6}; 下面哪个表达式的值与数组下标量总数相等?
A)m.length()
B)m.length
C)m.length()+1
D)m.length-1
答:D
13、方法 resume()负责恢复哪些线程的执行
A)通过调用 stop()方法而停止的线程。
B)通过调用 sleep()方法而停止的线程。
C)通过调用 wait()方法而停止的线程。
D)通过调用 suspend()方法而停止的线程。
答:D
14、有关线程的哪些叙述是对的
A)一旦一个线程被创建,它就立即开始运行。
B)使用 start()方法可以使一个线程成为可运行的,但是它不一定立即开始运 行。
C)当一个线程因为抢先机制而停止运行,它被放在可运行队列的前面。
D)一个线程可能因为不同的原因停止并进入可运行状态。
答:BCD
15、已知如下代码:
public class Test {
long a[] = new long [10];
public static void main(String arg[] ){
System.out.print(a[6]);
}
}
请问哪个语句是正确的?
A)Output is null.
B)Output is 0
C)When compile, some error will occur.
D)When running, some error will occur.
答:C
16、已知如下代码:
public class Test {
public static void main(String arg[] ) {
int i = 5;
do{
System.out.print(i);
}while(--i>5);
System.out.print(“finished”);
}
}
执行后的输出是什么?
A)5
B)4
C)6
D)finished
答:AD
17、已知如下代码:
switch (m) {
case 0:
System.out.print(“Condition 0”);
case 1:
System.out.print(“Condition 1”);
case 2:
System.out.print(“Condition 2”);
case 3:
System.out.print(“Condition 3”);
default:
System.out.print(“Other Condition ”);
}
当 m 的值为什么时能输出“Condition 2”
A)0 B)1 C)2 D)3 E) 4 F)None
答:ABC
18、下面的哪些声明是合法的?
A)long 1 = 4990
B)int i = 4L
C)float f =1.1
D)double d = 34.4
答:AD
19、给出如下代码:
class Test{
private int m;
public static void fun() {
//some code„
}
}
如何使成员变量 m 被函数 fun()直接访问?
A)将 private int m 改为 protected int m
B)将 private int m 改为 public int m
C)将 private int m 改为 static int m
D)将 private int m 改为 int m
答:C
20、以下哪个方法用于定义线程的执行体?
A)start()
B)init()
C)run()
D)main()
E)synchronized()
答:C
21、请看如下代码
class Person {
private int a;
public int change(int m) {
return m;
}
}
public class Teacher extends Person {
public int b;
public static void main(String arg[]) {
Person p = new Person();
Teacher t = new Teacher();
int i;
// point x
}
}
下面哪些放在// point x?行是正确的?
A i = m; B i = b; C i = p.a; D i = p.change(30); E i = t.b;
答:DE
22、给出下面的代码段:( )
public class Base{
int w, x, y, z;
public Base(int a, int b) {
x=a; y=b;
}
public Base(int a, int b, int c, int d) {
//assignment x=a, y=b w=d;z=c;
}
}
在代码说明//assignment x=a, y=b 处写下如下哪几个代码是正确的?
A)Base(a, b); B)x=a, y=b; C)x=a; y=b; D)this(a,b);
答:CD
23、给出下面代码:
public class Person{
static int arr[ ] =new int[10];
public static void main(String a [ ]){
System.out.println(arr[ 1 ]);
}
}
哪个选项是正确的?
A. 编译时将产生错误;
B. 编译时正确,运行时将产生错误;
C. 输出 0;
D. 输出空。
答:C
24、关于运算符>>和>>>描述正确的是
A. >>执行移动
B. >>执行翻转
C. >>执行有符号右移,>>>执行无符号右移
D. >>执行无符号右移,>>>执行有符号右移
答:C
25、下列关于栈的叙述正确的是
A 栈是非线性结构
B 栈是一种树状结构
C 栈具有先进先出的特征
D 栈具有后进先出的特征
答:D
26、选出 Java 语言中的关键词(多选)
A. NULL
B. sizeof
C. implements
D. extends
答:CD
27、现有下述代码,选择出能够打印出”Test2”的数字(多选)
switch(x){
case 1: System.out.println("Test1");
case 2:
case 3:
System.out.println("Test2");
break;
}
System.out.println("Test3");
A.0
B.1
C.2
D. 3
E. 4
答:CD
28、字符(char)的整型表示范围为
A. 0 . . . 32767
B. 0 . . . 65535
C. -256 . . . 255
D. -32768 . . . 32767
答:B
29、选择 Java 语言中的基本数据类型(多选)
A. byte
B. Integer
C. String
D. char
E. long
答:ADE
30、从下列选项中选择正确的 Java 表达式(多选)
A. int k=new String(“aa”);
B. String str=String(“bb”);
C. char c=74;
D. long j=8888;
答:CD
31、下述代码的执行结果为
public class foo {
static String s;
public static void main (String[]args) {
System.out.printIn (“s=” + s);
}
}
A.代码能够编译,打印出“s=”
B.代码能够编译,打印出“s=null”
C.代码不能够编译,因为 String s 没有初始化
D.代码能够编译,但是当调用 toString()时抛出 NullPointerException 异常
答:B
32、下述代码的执行结果是
class Super {
public int getLength() {
return 4;
}
}
public class Sub extends Super {
public long getLength() {
return 5;
}
public static void main (String[]args) {
Super sooper = new Super ();
Super sub = new Sub();
System.out.println(sooper.getLength()+ “,” + sub.getLength() );
}
}
A. 4, 4 B. 4, 5 C. 5, 4 D. 5, 5 E. 代码不能被编译
答:E
33、下述程序的执行结果为
int index = 1;
String [] test = new String[3];
String foo = test[index];
A. foo 的值为 “”
B. foo 的值为 null
C. 抛出一个异常
D. 程序不能够被编译
答:B
34、关于 Java 语言,下列描述正确的是(多选)
A. switch 不能够作用在 String 类型上
B. List, Set, Map 都继承自 Collection 接口
C. Java 语言支持 goto 语句
D. GC 是垃圾收集器,程序员不用担心内存管理
答:AD
35、指出下列程序运行的结果
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 ");
System.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
答:B
36、int[][] myArray=new int[][]{new int[]{5,6,2},new int[]{6,9,7,8,3},new int[]{3,2}};
myArray[2][2]的值是()
A. 9 B. 2 C. 6 D. 越界
答:D
37、下列描述中,那些符合 Java 语言的特征(多选)
A. 支持跨平台(Windows,Linux,Unix 等)
B. GC(自动垃圾回收),提高了代码安全性
C. 支持类 C 的指针运算操作
D. 不支持与其它语言书写的程序进行通讯
答:ABD
38、关于异常(Exception),下列描述正确的是(多选) A. 异常的基类为 Exception,所有异常都必须直接或者间接继承它 B. 异常可以用 try{ . . .}catch(Exception e){ . . .}来捕获并进行处理 C. 如果某异常继承 RuntimeException,则该异常可以不被声明 D. 异常可以随便处理,而不是抛给外层的程序进行处理 答:ABC
39、(单选)声明一个委托 public int myCallBack(int x); 则用该委托产生的回调方 法的原型应该是
A. void myCallBack(int x)
B. int receive(int num)
C. String receive(int x)
D. 不确定的
答:B
40、(单选)下面的代码实现了设计模式中的什么模式
public class A {
private A instance;
private A() { }
public static A getInstance {
if ( A == null )
instance = new A();
return instance;
}
}
A. Factory
B. Abstract Factory
C. Singleton
D. Builder
答:C
41、class Class1 { public static int Count = 0;
public Class1() { Count++; } } public static void main(String args[]){
Class1 o1 = new Class1(); Class1 o2 = new Class1(); } 请问,Class1.Count 的值是多少?( ) A. 1 B. 2 C. 3 D. 4 答:B
42、三种字符串判空串方法:
1: bool isEmpty = (str.length() == 0);
2: bool isEmpty = (str == String.Empty);
3: bool isEmpty = (str == "");
哪种方法正确?
A. 1 B. 2 C. 3
答:A
43、MAX_LENGTH 是 int 型 public 成员变量,变量值保持为常量 100,用简 短语句定义这个变量。
A .public int MAX_LENGTH=100;
B. final int MAX_LENGTH=100;
C. final public int MAX_LENGTH=100;
D. public final int MAX_LENGTH=100;
答:CD
44、 String s=new String(“hello”);
String t =new String(“hello”);
char c [ ] ={„h‟,‟e‟,‟l‟,‟l‟,‟o‟};
下列哪些表达式返回 true ?
A.s.equals(t);
B.t.equals(c);
C.s= =t ;
D.t.equals (new String(“hello”));
E.t= = c;
答:AD
45、类 Teacher 和 Student 是类 Person 的子类;
Teacher t;
Student s;
// t and s are all non-null.
if (t instanceof Person ){
s=(Student)t;
}
最后一条语句的结果是:
A.将构造一个 Student 对象;
B.表达式是合法的;
C.表达式是错误的;
D.编译时正确, 但运行时错误。
答:D
46、给出下面代码段(多选)
switch (m)
{
case 0 :
System.out.println(“case 0”);
case 1:
System.out.println(“case 1”);
break;
case 2:
default :
System.out.println(default”);
}
下列 m 的哪些值将引起 “default ”的输出?
A.0 B. 1 C. 2 D. 3
答:CD
47、下列哪些说法是正确的?
A. Java 语言只允许单一继承
B. Java 语言只允许实现一个接口
C. Java 语言不允许同时继承一个类并实现一个接口
D. Java 语言的单一继承使得代码更加可靠.
答:AD
48、main 方法的返回类型是:
A.int B.void C.boolean D.static E. public
答:B
49、给定下列代码:
public void test() {
try {
oneMethod();
System.out.println( “condition 1”);
} catch (ArrayIndexOutOfBoundsException e){
System.out.println(“condition 2”);
}catch(Exception e){
System.out.println(“condition 3”);
}finally{
System.out.println(“finally”);
}
}
oneMethod 正常运行, 将显示?
A. condition 1 B. condition 2 C. condition 3 D. finally
答:AD
50、下列代码哪几行会出错
1) public void modify() {
2) int I, j, k;
3) I=100;
4) while(I>0){
5) j=I*2;
6) System.out.println(“The value of j is “ +j);
7) k=k+1;
8) I--;
9) }
10) }
A. line 4 B. line 6 C. line 7 D. line 8
答:C
51、对于下列代码
public class Parent {
public int addValue (int a ,int b ){
int s;
s = a + b;
return s;
}
}
class Child extends Parent {
}
下述哪些方法可以加入类 Child?
A . int addValue(int a ,int b){//do something…}
B. public void addValue(){//do something…}
C. public int addValue(int a ){//do something…}
D. public int addValue( int a, int b )throws MyException {//do something…} 答:BC
52、请选出下面两个类间关系描述错误的项
a. public interface A {} public class B extends A {}
b. public interface A {} public interface B extends A {}
c. public interface A {} public class B implements A {}
d. public class A {} public class B { protected A a;}
答:A
53、下面正确的是
A)float f = 3.14;
B)byte i = 225;
C)long k = 33;
D)int p[ ][ ];
答:CD
54、下列创建数组的方法正确的是
A)int two Dim[ ][ ] = new int[4][ ];
B)int two Dim[ ][ ] = new int[ ][4];
C)int two Dim[ ][ ] = new int[4][5];
D)char a[ ] = {‘A’, ‘B’};
E)char c[ ] = “ABC” ;
答:ACD
55、关于线程设计,下列描述正确的是
A. 线程对象必须实现 Runnable 接口
B. 启动一个线程直接调用线程对象的 run()方法
C. Java 提供对多线程同步提供语言级的支持
D. 一个线程可以包含多个进程
答:C
56、public class X extends Thread implements Runnable{
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 程序会运行和启动
答:D
57、根据线程安全的相关知识,分析以下代码,当调用 test 方法时 i>10 时是否 会引起死锁?
public void test(int i) {
lock(this) {
if (i>10) {
i--;
test(i);
}
}
}
A. 会锁死 B. 不会锁死
答:B
58、欲构造 ArrayList 类得一个实例,此类实现了 List 接口,下列哪个方法是正 确的:
A ArrayList myList = new Object();
B List myList = new ArrayList();
C ArraylList myList = new List();
D List myList = new List();
答:B
59、Which of the following are methods of the Runnable interface。
A. run B. start C. yield D. stop
答:A
60、Java 网络程序设计中,下列正确的描述是(多选)
A. Java 网络编程 API 建立在 Socket 基础之上
B. Java 网络接口只支持 TCP 以及其上层协议
C. Java 网络接口只支持 UDP 以及其上层协议
D. Java 网络接口支持 IP 以上的所有高层协议
答:AD
61、Java I/O 程序设计中,下列描述正确的是 A. OutputStream 用于写操作 B. InputStream 用于写操作 C. I/O 库不支持对文件可读可写 API 答:A
62、选出对于 XML 的评论正确的选项
A. XML 是一种语言无关平台无关的自描述语言。
B. 标签实际上包含了元素和属性两部分。用元素来描述有规律的数据,用属性 来描述系统数据。
C. XML 不可跨平台,不具备扩展性。
D.XML 文档中的每一个元素都处在一个名字空间中;如果没有指定的名字空间, 缺省的名字空间就是和该元素相关联的名字空间。
答:AD
63、(单选)What compiler switch creates an xml file from the xml comments in the files in an assembly?
A. /text B. /doc C. /xml D. /help
答:C
64、说说下面语句是否有错误,或可能出现的缺陷,并指出错误,或缺陷在哪 里?
public class MyFile implements Runnable{
public void run(){
while (true){
try{
FileReader fr=new FileReader(new File("a.txt")) ;
String line=fr.readLine();
System.out.println(line);
}catch(IOException err) { }
Sleep(1000);
}
}
答:1.fr.readLine()没有这个方法
2.Sleep(1000)需要用 Thread.sleep(1000);
3.没有关闭 FileReader
4.死循环,没有退出的可能
65、判断下列语句是否正确,如果有错误,请指出错误所在?
List<Short> a = new ArrayList<Short>();
a.add(5);
答:错误,5 的默认类型为 int。
66、判断下列语句是否正确,如果有错误,请指出错误所在?
void foo(final int []arg){
if (arg.length > 1)
arg[0] = 5;
}
答:正确
67、判断下列语句是否正确,如果有错误,请指出错误所在?
interface A{
int add(final A a);
}
class B implements A{
long add(final A a){
return this.hashCode() + a.hashCode();
}
}
答:错误,返回值不是 long 类型
68、指出下面程序的运行结果:
class A{
static{
System.out.print("a");
}
public A (){
System.out.print("x");
}
}
class B extends A{
static{
System.out.print("b");
}
public B (){
System.out.print("y");
}
}
public class Test{
public static void main(String[] args){
A ab = new B ();
ab = new B ();
}
}
答:abxyxy
69、下列代码的输出结果是什么?
public class MyFor {
public static void main (String argv[]){
int i;
int j;
outer:for(i=1;i<3;i++)
inner:for(j=1;j<3;j++){
if (j==2)
continue outer;
System.out .println("Value for i="+i+"Value for j=" +j);
}
}
}
答:Value for i=1Value for j=1
Value for i=2Value for j=1
70、查看下面的代码,写出可以使程序正常执行的修改方法
public class MyClass {
static String s1;
String s2;
public static void main(String args[]) {
String s3
System.out.println("s1 =" + s1);
System.out.println("s2 =" + s2);
System.out.println("s3 =" + s3);
}
}