面试应聘的JAVA笔试题和答案 下载本文

一、选择题

1:List, Set, Map是否继承自Collection接口

A:都是,B 都不是 C:List, Set 是 D:Set, Map 是 正确答案 C

2:下面描述哪个是正确的

A:构造器Constructor可被override

B:可以继承String类

C:try {}里有一个return语句,那么紧跟在这个try后的finally {}里的code不会被执行

D:两个对象值相同(x.equals(y) == true),那么也有相同的hash code 正确答案 D

3 abstract的method是否可同时是static,是否可同时是native,是否可同时是synchronized

A:都能 B:都不能 C:可以为static D:可以为native 正确答案 A

4:下面的程序中,temp的最终值是什么? long temo=(int)3.9; temp%=2;

A: 0 B :1 C :2 D : 3

正确答案 B

5、请在以下选项中选出非基本数据类型的选项 ( )

A: int B:byte C: boolean D:String

正确答案 D

6、阅读下面代码段, 给出以下代码的输出结果 public class Test{

public static void main(String args[]) {

String str1 = \ String str = \

String str2 = new String(\

System.out.println(str1 == str2); System.out.println(str1.equals(str2)); System.out.println(str == str1); } }

A:true,true,true 正确答案 D

B:true,false,true C:true,true,false D:false,true,true

7、阅读下面代码段, 给出以下代码的输出结果:

int i=1; switch (i) { case 0:

System.out.println(\ break; case 1:

System.out.println(\ case 2:

System.out.println(\ default:

System.out.println(\ } A:

B:

:

正确答案 C

8、阅读下面代码段, 给出以下代码的输出结果

public class MyClass{ static int i;

public static void main(String argv[]){ System.out.println(i);

}

}

A: Error Variable i may not have been initialized B:null C:正确答案 D

9、阅读下面代码段, 给出以下代码的输出结果:

class A{ static{

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

public A(){

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

class B extends A{ static{

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

public B(){

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

public class Hello{

public static void main(String[] args){ A ab = new B(); ab = new B();

} }

A:A1B1A2B2B1B2 B:A1B1A2B2A2B2 C:A1B1A2B2B1B2 D:A1A2B1B2A2B2 正确答案 B

D:default

D:0

10、阅读下面代码段, 给出以下代码的输出结果

public class TestData {

} }

A.test1 B.test2 C.null D.”” 正确答案 A

public String getValue () { }

TestData test = new TestData(); String a = test.getValue(); System.out.println(a);

String value = \try{ }

return value;

value = \return value; e.printStackTrace(); value = \

}catch(Exception e){ }finally{

public static void main(String args[]){

二、改错题,如果有错误,请指出并修正。

1、

interface A{ int x = 0; }

class B{

int x =1; }

class C extends B implements A { public void pX(){

System.out.println(x); }

public static void main(String[] args) { new C().pX(); } }

答案:错误。在编译时会发生错误(错误描述不同的JVM有不同的信息,意思就是未明确的x调用,两个x都匹配(就象在同时import java.util和java.sql两个包时直接声明Date一样)。对于父类的变量,可以用super.x来明确,而接口的属性默认隐含为 public static final.所以可以通过A.x来明确。

2、

class Data {