网络公司招聘java工程师笔试题

进修社 人气:2.41W

选择题

网络公司招聘java工程师笔试题

1:

what will be printed when you execute the following code?

class x

{

y b = new y();

x()

{

system.out.print("x");

}

}

class y

{

y()

{

system.out.print("y");

}

}

public class z extends x

{

y y = new y();

z()

{

system.out.print("z");

}

public static void main(string[] args)

{

new z();

}

}

choices:

what will be printed when you execute the following code?

class x

{

y b = new y();

x()

{

system.out.print("x");

}

}

class y

{

y()

{

system.out.print("y");

}

}

public class z extends x

{

y y = new y();

z()

{

system.out.print("z");

}

public static void main(string[] args)

{

new z();

}

}

choices:

a.z

b.yz

c.xyz

d.yxyz

2:

1. public class x {

2. public object m () {

3. object o = new float (3.14f);

4. object [] oa = new object [1];

5. oa[0]= o;

6. o = null;

7. oa[0] = null;

8.return o;

9. }

10.}

when is the float object created in line 3, eligible for garbage collection?

1. public class x {

2. public object m () {

3. object o = new float (3.14f);

4. object [] oa = new object [1];

5. oa[0]= o;

6. o = null;

7. oa[0] = null;

8.return o;

9. }

10.}

when is the float object created in line 3, eligible for garbage collection?

a.just after line 5

b.just after line 6

c.just after line 7

d.just after line 8(that is, as the method returns)

3:which statement about the garbage collection mechanism are true?

a.garbage collection require additional programe code in cases where multiple threads are running.

b.the programmer can indicate that a reference through a local variable is no longer of interest.

c.the programmer has a mechanism that explicity and immediately frees the memory used by java objects.

d.the garbage collection mechanism can free the memory used by java object at explection time.

4:which declares for native method in a java class corrected?

a.public native void method(){}

b.public native void method();

c.public native method();

d.public void native method();

5:which are not java keywords?

a.true

b.const

c.super

d.void

6:which statement about listener is true?

a.most component allow multiple listeners to be added.

b.if multiple listener be add to a single component, the event only affected one listener.

c.component don?t allow multiple listeners to be add.

d.none

7:

public class outerclass {

private double d1 = 1.0;

//insert code here

}

you need to insert an inner class declaration at line 3. which two inner class declarations are

valid?

public class outerclass {

private double d1 = 1.0;

//insert code here

}

you need to insert an inner class declaration at line 3. which two inner class declarations are

valid?

a.class innerone{ public static double methoda() {return d1;} }

b.public class innerone{ static double methoda() {return d1;} }

c.private class innerone{ double methoda() {return d1;} }

d.static class innerone{ protected double methoda() {return d1;} }

8:public class parent {

int change() {…}

}

class child extends parent {

}

which methods can be added into class child?

a.public int change(){}

b.abstract int chang(){}

c.private int change(){}

d.none

9:

what will happen when you attempt to compile and run the following code?

class base

{

int i = 99;

public void amethod()

{

system.out.println("base.amethod()");

}

base()

{

amethod();

}

}

public class derived extends base

{

int i = -1;

public static void main(string argv[])

{

base b = new derived();

system.out.println(b.i);

b.amethod();

}

public void amethod()

{

system.out.println("derived.amethod()");

}

}

choices:

what will happen when you attempt to compile and run the following code?

class base

{

int i = 99;

public void amethod()

{

system.out.println("base.amethod()");

}

base()

{

amethod();

}

}

public class derived extends base

{

int i = -1;

public static void main(string argv[])

{

base b = new derived();

system.out.println(b.i);

b.amethod();

}

public void amethod()

{

system.out.println("derived.amethod()");

}

}

choices:

a.derived.amethod() -1 derived.amethod()

b.derived.amethod() 99

c.compile time error

d.derived.amethod()

10:

what is the result when you compile and run the following code?

public class throwsdemo

{

static void throwmethod()

{

system.out.println("inside throwmethod.");

throw new illegalaccessexception("demo");

}

public static void main(string args[])

{

try

{

throwmethod();

}

catch (illegalaccessexception e)

{

system.out.println("caught " + e);

}

}

}

choices:

what is the result when you compile and run the following code?

public class throwsdemo

{

static void throwmethod()

{

system.out.println("inside throwmethod.");

throw new illegalaccessexception("demo");

}

public static void main(string args[])

{

try

{

throwmethod();

}

catch (illegalaccessexception e)

{

system.out.println("caught " + e);

}

}

}

choices:

a.compilation error

b.runtime error

c.compile successfully, nothing is printed.

d.inside throwmethod. followed by caught:java.lang.illegalaccessexcption: demo

11:what is written to the standard output given the following statement:system.out.println(4|7);

select the right answer:

a.4

b.5

c.6

d.7

12:

give the code fragment:

if(x>4){

system.out.println(“test 1”);}

else if (x>9){

system.out.println(“test 2”);}

else {

system.out.println(“test 3”);}

which range of value x would produce of output “test 2”?

give the code fragment:

if(x>4){

system.out.println(“test 1”);}

else if (x>9){

system.out.println(“test 2”);}

else {

system.out.println(“test 3”);}

which range of value x would produce of output “test 2”?

a.x<4

b.x>4

c.x>9

d.none

13:

the following code is entire contents of a file called example.java,causes precisely one error during compilation:

class subclass extends baseclass{

}

class baseclass(){

string str;

public baseclass(){

system.out.println(“ok”);}

public baseclass(string s){

str=s;}}

public class example{

public void method(){

subclass s=new subclass(“hello”);

baseclass b=new baseclass(“world”);

}

}

which line would be cause the error?

the following code is entire contents of a file called example.java,causes precisely one error during compilation:

class subclass extends baseclass{

}

class baseclass(){

string str;

public baseclass(){

system.out.println(“ok”);}

public baseclass(string s){

str=s;}}

public class example{

public void method(){

subclass s=new subclass(“hello”);

baseclass b=new baseclass(“world”);

}

}

which line would be cause the error?

a.9

b.10

c.11

d.12

14:

public class x{

public object m(){

object o = new float(3.14f);//line 3

object [] oa = new object[1];//line 4

oa[0] = o;//line 5

o=null;//line 6

return oa[0];//line 7

}

}

when is the float object, created in line 3,eligible for garbage collection?

public class x{

public object m(){

object o = new float(3.14f);//line 3

object [] oa = new object[1];//line 4

oa[0] = o;//line 5

o=null;//line 6

return oa[0];//line 7

}

}

when is the float object, created in line 3,eligible for garbage collection?

a.just after line 5.

b.just after line 6

c.just after line 7(that is,as the method returns)

d.never in this method

15:a class design requires that a member variable should be accessible only by same package, which modifer word should be used?

a.protected

b.public

c.no modifer

d.private

16:

给出下面的代码片断。。。下面的哪些陈述为错误的?

1) public void create() {

2) vector myvect;

3) myvect = new vector();

4) }

给出下面的代码片断。。。下面的哪些陈述为错误的.?

1) public void create() {

2) vector myvect;

3) myvect = new vector();

4) }

a.第二行的声明不会为变量myvect分配内存空间。

b.第二行语句创建一个vector类对象。

c.第三行语句创建一个vector类对象。

d.第三行语句为一个vector类对象分配内存空间

简答题

17:硬盘上保存有一个密码表,文本文件格式,文件名为“code.txt”,内容如下:

abcdefghijklmnopqrstuvwxyz

ushecginpaywdqmlxbozrtfvjk

试编写程序实现一个简单的加密程序,循环读取用户输入,按此密码表将字符进行替换,

并直接打印输出;例如“baidu”将被替换成“super”。

18:循环的有序数组(比如1,2,3,4,5,-3,-2,-1这种数列)里查找一个数。

19:请问你在什么情况下会在你的java代码中使用可序列化?为什么放到httpsession中的对象必须要是可序列化的?

20:不允许使用系统时间,写出一个随机数生成函数。

21:介绍java中的collection framework(包括如何写自己的数据结构)?

22:谈谈final, finally, finalize的区别。

23:spring的容器的实际代表者是哪个类(接口),该类常见的子类有那些?

24:简单介绍一下ioc的实现原理。(写出代码最好)

25:简述 jdbc 的基本功能。