求职宝典

6.2 笔试真题 & 详解

一、 单选题(18分,每小题个2分)

1.关于软件测试的目的,下面观点错误的是()

A、未来发现错误而执行程序的过程

B、一个好的测试用例能够发现至今尚未发现的错误

C、证明程序是正确、没有错误的

D、一个成功的测试用例是发现了至今尚未发现的错误的测试

2.Given:

Integer i = new Integer(42);

Long l = new Long(42);

Double d = new Double(42.0);

Which expression evaluates to True?

A. (i == l)

B. (i == d)

C. (d == 1)

D. (i.equals(d))

E. (d.equals(l))

F. (i.equals(l))

G. (l.equals(42L))

3.What happens when you try to compile and run the following application?Choose all

Correct options.

1. public

class Z {

2. public

static

void main(String[] args) {

3. new Z();

4. }

5.

6. Z() {

7. Z alias1 =

this;

8. Z alias2 =

this;

9.

synchronized (alias1) {

10.

try {

11. alias2.wait();

12. System.out.println("DONE WAITING");

13. }

14.

catch (InterruptedException e) {

15. System.out.println("INTERRUPTED");

16. }

17.

catch (Exception e) {

18. System.out.println("OTHER EXCEPTION");

19. }

20.

finally {

21. System.out.println("FINALLY");

22. }

23. }

24. System.out.println("ALL DONE");

25. }

26. }

A.The application compiles and prints “DONE WAITING”

B.The application compiles but doesn’t print anything

C.The application compiles and print “FINALLY”

D.The application compiles and print “ALL DONE”

E.The application compiles and print “INTERRUPTED”

F.The application compiles and print “DONE WAITING” and “FINALLY”

4.Consider the following classes:

1. class Person{

2.

public

void printValue(

int i,

int j){/*.....*/}

3.

public

void printValue(

int i){/*....*/}

4. }

5. public

class Teacher

extends Person{

6.

public

void printValue(){/*...*/}

7.

public

void printValue(

int i){/*...*/}

8.

public

void printValue(String i){/*...*/}

9.

public

static

void main(String args[]){

10. Person t =

new Teacher();

11.

char ch = 'y';

12. t.printValue(ch);

13. }

14.}

Which of the statements below is true?

A. Line 7 will not compile, because void methods cannot be overridden

B. Line 12 will not compile, because there is no version of printValue() that takes a char argument

C. The code will compile but will throw an exception at line 12 at runtime

D. The statement on line 12 will invoke the method on line 8

E. The statement on line 12 will invoke the method on line 2

F. The statement on line 12 will invoke the method on line 3

G. The statement on line 12 will invoke the method on line 7

5.Consider the following statement, choose all correct options

You are given a class hierarchy with an instance of the Class Dog. The class Dog is a child of

Mammal and the class Mammal is a child of the class Vertebrate. The class Vertebrate has a method called move which prints out the string “move” . The class Mammal overrides this method and prints out the string”walks”. The class Dog overrides this method and prints out the string “walks on paws”.

Given an instance(dog) of the class Dog,how can you access the ancestor method move in Vertebrate so it prints out the string “move”;

A. dog.super().super().move();

B. dog.parent().parent().move();

C. dog.move();

D. none of the above

6.What will happen when you attempt to compile and run the following code.

public

class Test {

public

static

void main(String argv[]) {

HHQ ht =

new HHQ("my name");

ht.start();

}

}

class HHQ

extends Thread {

private String name = "";

HHQ(String s) {

name = s;

}

public

void run() {

inner();

System.out.println("finished");

}

public

void inner() {

while (

true) {

try {

System.out.println("waiting");

wait();

}

catch (InterruptedException ie) {

}

System.out.println(name);

notifyAll();

}

}

}

A. It will cause a compile time error

B. Compilation and output of “waiting”

C. Compilation and output of “waiting” followed by “finished”

D. Runtime error, output of “waiting” and an exception will be thrown

7.Which of the following most closely describes the process of overriding?

A.A class with the same name replaces the functionality of a class defined earlier in the hierarchy

B.A method with the same name completely replaces the functionality of a method earlier in the hierarchy

C.A method with the same name but different parameters gives multiple uses for the same method name

D.A class is prevented from accessing methods in its immediate ancestor

8.Given the following code:

1 class A{

2

public

void process(){System.out.print("A");}}

3 class B

extends A{

4

public

void process()

throws IOException{

5

super.process();

6 System.out.print("B");

7

throw

new IOException();

8 }

9

public

static

void main(String[] args) {

10

try{

11

new B().process();

12 }

catch(IOException e){

13 System.out.println("Exception");

14 }

15 }

16 }

What will happen when you attempt to compile and run it?

A. The program will run and output “A”,”B” and “Exception”

B. The program will run and output “A”

C. The program will run and output “B” and “Exception”

D. Compilation fails because of an error in line 11

E. Compilation fails because of an error in line 4

F. An IOException will thrown at runtime

9.What will happen when you attempt to compile and run the following code in JDK 5 environment?

1.

public

class Test{

2.

public

static

void increase(Integer i){

3. i++;

4.}

5.

public

static

void main(String args[]){

6. Integer i =

new Integer(0);

7. increase(i);

8. System.out.println(i);

9. }

10.}

A.Compilation fails because of an error in line 7

B.Compilation fails because of an error in line 3

C.The program will run and output “1”

D.The program will run and output a random number

E.The program will run and output “0”

二、不定项选择题(18分,每小题各2分)

1.下述表达正确的有()

A、单元测试应该由试人员进行测试

B、软件质量是不可量化的

C、开发人员应该对代码质量负最主要的责任

D、软件配置管理的好坏对软件的最终质量没有影响

E、软件运行性能是由硬件配置所制约的,与程序所用的数据结构与算法无关

2.Which of the following demonstrate a “has a”relationship?

A、public interface Person{ }

public class Employee extends Person{ }

B、public interface Shape { }

public interface Rectangle 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 Componet{

private Component[] children;

}

3.Which of the following are true for the class java.util.TreeSet?

A.The elements in the collection are ordered

B.The collection is guaranteed to be immutable

C.The elements in the collection are guaranteed to be unique

D.The elements in the collection are accessed using a unique key

E.The elements in the collection are guaranteed to by synchronized

4.Given the following code fragment:

1.

public

void create(){

2. Vector myVect;

3. myVect =

new Vector();

4.}

Which of the following statement are true?

A. The statement on line 2 creates an object of class Vector

B. The declaration on line 2 does not allocate memory space for the variable myVect

C. The declaration on line 2 allocates memory space for a reference to a Vector object

D. The statement on line 3 create an object of class Vector

E. The statement on line 3 allocates memory space for an object of class Vector

5.Given the following code:

class Base{

static

int oak=99;

}

public

class Doverdale

extends Base{

public

static

void main(String argv[]){

Doverdale d =

new Doverdale();

d.amethod();

}

public

void amethod(){

//Here

}

}

Which of the following if placed after the comment//Here,will compile and modify the value of the variable oak?

A. super.oak=1;

B. oak=33;

C. Base.oak=22;

D. Oak=50.1;

6.Which of the following statements are true about a variable created with the static modifier?

A.Once assigned the value of a static variable can’t be altered

B.A static variable created in a method will keep the same value between calls

C.Only one instance of a static variable will exist for any amount of class instances

D.The static modifier can only be applied to a primitive value

7.Given the following class:

public

class A{

public

static

void main(String argv[]){

boolean b1 =

true;

if((b1==

true)||place(

true)){

System.out.println("Hello True");

}

if(b1 | place((String)

null)){

System.out.println("Hello Null");

}

}

public

static

boolean place(

boolean location){

if(location!=

true){

System.out.println("world True");

}

System.out.println("World True");

return

true;

}

public

static

boolean place(String str){

if(str ==

null | str.length() == 0){

System.out.println("World Null");

}

System.out.println("World String");

return

true;

}

What will happen when you attempt to compile and run it?

A. Compile fails

B. Output of “Hello True”

C. Output of “World Boolean” followed by “Hello True”,”World Null”,”World String” and “Hello Null”

D. Output of “Hello True” followed by “Hello Null”

E. Output of “Hello True”, then an exception is thrown at runtime

F. Output of “Hello True“ followed by “World null”,”World String” and “Hello Null”

8.Which statement are true about the garbage collection mechanisms?

A.The garbage collection mechanism release memory at predictable times

B.A correct program must not depend upon the timing or order of garbage collection

C.Garbage collection ensures that a program will not run out of memory during execution

D.The programmer can indicate that a reference through a local variable is no longer going to Java objects

E.The programmer has a mechanism that explicitly and immediately frees the memory used by Java objects

F.The garbage collection system never reclaims memory from objects while are still accessible to running user threads

9.What will happen when you attempt to compile and run the following code?

1.pu

blic

class Test{

2.

public

static String hello(String[] strs,String s2){

3. strs[0] = "<" + strs[0] + ">";

4. s2.toUpperCase();

5.

return s2;

6.}

7.

public

static

void main(String args[]){

8. String a =

new String("t");

9. String[] b =

new String[]{"t"};

10. String c = a.intern();

11.

if(a.equals(b[0])){

12. System.out.print("1");

13. }

14.

if(b[0] == c){

15. System.out.print("2");

16. }

17.

if(a == c){

18. System.out.print("3");

19. }

20. a = hello(b,c);

21. System.out.print(a);

22. System.out.print(b[1]);

23. System.out.print(c);

24. }

25.}

A.The program will run and output “12t<t>t”

B.The program will run and output “123T<t>t”

C.The program will run and output “12T<t>t”

D.Compilation fails because of an error in line 4

E.Compilation fails because of an error in line 9

F.The program will run and output “12ttt”

三、填空题(每空3分,共51分)

1、如下的代码实现了先进先出队列,请按注释要求填空。(每空各3分,共9分)

class FifoQueue{

private

transient Node head;

private

transient Node last;

Node enq(Object x){ //入队

Node p =

new Node(x);

if(last ==

null)

last = head = p;

else

[1] ; //请在此补充一条语句

return p;

}

Node deq(){ //出队

Node p = head;

if( [2] ){ //请在此补充一条表达式

if((head = p.next) ==

null)

[3]; //请在此补充一条语句

p.next =

null;

}

return p;

}

static

final

class Node{

/** The item being transferred */

Object item;

/** Next node in wait queue */

Node next;

/** Creates a node with initial item */

Node(Object x) { item = x; }

}

}

2.如下的代码采用合并排序对数组进行排序,请按注释要求填空。(每空各3分,共21分)

import java.lang.reflect.Array;

import java.util.Random;

public

class Test{

//将数组src中的Integer类型的元素按增序排列

public

static

void main(String[] argv){

Object[] src =

new Object[100];

for(

int i = 0;i < src.length;i++){

src[i] =

new Random().nextInt();

}

Object[] aux = cloneArray(src);

mergeSort(aut,src,0,src.length);

for(

int i = 0;i < src.length;i++){

System.out.print(src[i] + ",");

}

}

/**

* Src is the source array that starts at index 0.数组元素实现java.lang.Comparable接口

* Dest is the destination array that starts at index 0.数组元素实现java.lang.Comparable接口

* low is the index in dest to start sorting

* high is the end index in dest to end sorting

*/

private

static

void mergeSort(Object[] src,Object[] dest,

int low,

int high){

int length = high - low;

//Insertion sort on smallest arrays. 当待排序元素的个数少于5时,采用插入排序

if(length < 5){

for(

int i = low;i < high; i++){

if(((Comparable)dest[j-1]).compareTo(dest[j]) > 0){

Object t = dest[j];

[4]; //请在此补充一条语句

[5]; //请在此补充一条语句

}

}

return;

}

//Recursively sort halves of dest into src

int mid = (low + high) >> 1;

mergeSort(dest,src,low,mid);

[6]; //请在此补充一条语句

//If list is already sorted,just copy from src to dest.This is an

//optimization that results in faster sorts for nearly ordered lists.

if( [7] ){ //请在此补充一条表达式

System.arraycopy(src, low, dest, low, length);

return;

}

//Merge sorted halves (now in src) into dest

int p = low;

[8]; //请在此补充一条语句

for(

int i = low;i < high; i++){

if( [9] //请在此补充一条表达式

|| p < mid && ((Comparable)src[p]).compareTo(src[q]) <=0){

dest[i] = src[p++];

}

else {

[10]; //请在此补充一条语句

}

}

}

/**

*Clones an array within the specified bounds. This method assumes that a

*is an array.

*/

private

static <T> T[] cloneArray(T[] a){

int n = a.length;

T[] result = (T[])Array.newInstance(a.getClass().getComponentType(), n);

System.arraycopy(a, 0, result, 0, n);

return result;

}

}

3.以下为JDK1.5中java.util.HashMap(哈希表)的实现,请根据给出的代码片段,完成put方法的填空(每空各3分,共6分)

package java.util;

import java.io.*;

import java.security.KeyStore.Entry;

public

class HashMap<K,V>

extends AbstractMap<K,V>

implements Map<K,V>,Cloneable,Serializable

{

/**

* The table,resized as necessary.Length must always be a power of two.

*/

transient Entry[] table;

/**

*The number of key-value mappings contained in this identity hash map.

*/

transient

int size;

/**

* The next size value at which to resize (capacity * load factor).

*/

int threshold;

/**

* The number of times this HashMap has been structurally modified

* Structural modifications are those that change te number of mappings in

* the HashMap or otherwise modify its internal structure(e.g.

* rehash).This field is used to make iterators on Collection-views of

* the HashMap fail-fast. (See concurrentModificationException)

*/

transient

volatile

int modCount;

//其它代码段...省略

/**

* Associates the specified value with the specified key in this map.

* If the map previously contained a mapping for this key,the old

* value is replaced.

*

*

@param key key with which the specified value is to be associated.

*

@param value value to be associated with the specified key.

*

@return previous value associated with specified key,or null

* if there was no mapping for key.A null</tt>return can

* alse indicate that the hashMap previously associated

* null with the specified key.

*/

public V put(K key,V value){

if(key ==

null)

return putForNullkey(value);

int hash =hash( [11] ); //请在此补充一条表达式

int i = indexFor(hash,table.length);

for(Entry<K,V> e = talbe[i];e !=

null;e=e.next){

Object k;

if(e.hash == hash && ((k = e.key) == key || [12] )){ //请在此补充一条表达式

V oldValue = e.value;

e.value = value;

e.recordAccess(

this);

return oldValue;

}

}

modCount++;

addEntry(hash,key,value,i);

return

null;

}

static

int hash(

int h){

h ^= (h >>> 20) ^ (h >>> 12);

return h ^ (h >>> 7) ^ (h >>> 4);

}

/**

* Returns index for hash code h.

*/

static

int indexFor(

int h,

int length){

return h & (length-1);

}

}

4.请阅读以下代码,并根据代码上下文完成填空。 (每空各3分,共15分)

package examination;

import java.util.concurrent.locks.Condition;

import java.util.concurrent.locks.Lock;

import java.util.concurrent.locks.ReentrantLock;

public

class ThreadSafeBuffer{

final Lock lock =

new ReentrantLock();

final Condition notFull = lock.newCondition();

final Condition notEmpty = lock.newCondition();

final Object[] data =

new Object[1024];

int putptr,takeptr,count;

public

void put(Object x)

throws InterruptedException {

lock.lock();

try{

[13]{ //请在此补充一条语句

[14]; //请在此补充一条语句

}

data[putptr] = x;

if(++putptr == data.length){

putptr = 0;

}

++count;

[15]; //请在此补充一条语句

}

finally {

lock.unlock();

}

}

public Object take()

throws InterruptedException{

lock.lock();

try{

[16]{ //请在此补充一条语句

[17]; //请在此补充一条语句

}

Object x = data[takeptr];

if(++takeptr == data.length){

takeptr = 0;

}

--count;

notFull.signal();

return x;

}

finally {

lock.unlock();

}

}

}

更多柳工机械笔试真题及答案:https://bbs.yjbys.com/bjfx/

 

《柳工机械求职宝典》

《柳工机械求职宝典Word下载》

《柳工机械求职宝典PDF下载》

Copyright©2006-2024应届毕业生网yjbys.com版权所有