大家帮帮忙,看看这几道面试题应该选什么?

shutao 2010-03-16 10:28:07
In the following code, which is the earliest statement, where the object originally held in e, may be garbage collected:
1.public class Test {

2. public static void main (String args []) {

3. Employee e = new Employee("Bob", 48);

4. e.calculatePay();

5. System.out.println(e.printDetails());

6. e = null;

7. e = new Employee("Denise", 36);

8. e.calculatePay();

9. System.out.println(e.printDetails());

10. }

11.}
Only One:
A.Line 10
B.Line 11
C.Line 7
D.Line 8


3:
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


4:
Give the following method:
public void method( ){
String a,b;
a=new String(“hello world”);
b=new String(“game over”);
System.out.println(a+b+”ok”);
a=null;
a=b;
System.out.println(a);
}
In the absence of compiler optimization, which is the earliest point the object a refered is definitely elibile to be garbage collection.
A.before line 5
B.before line 6
C.before line 7
D.before line 9


5:下面关于变量及其范围的陈述哪些是错的。
A.实例变量是类的成员变量。
B.实例变量用关键字static声明。
C.在方法中定义的局部变量在该方法被执行时创建
D.局部变量在使用前必须被初始化。


6:
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;} }


7:软件生命周期的瀑布模型把软件项目分为3个阶段、8个子阶段,以下哪一个是正常的开发顺序?
A.计划阶段、开发阶段、运行阶段
B.设计阶段、开发阶段、编码阶段
C.设计阶段、编码阶段、维护阶段
D.计划阶段、编码阶段、测试阶段


8:
What will happen when you attempt to compile and run the following code?

(Assume that the code is compiled and run with assertions enabled.)

public class AssertTest{

public void methodA(int i){

assert i >= 0 : methodB();

System.out.println(i);

}

public void methodB(){

System.out.println("The value must not be negative");

}

public static void main(String args[]){

AssertTest test = new AssertTest();

test.methodA(-10);

}

}
A.it will print -10
B.it will result in AssertionError showing the message-“the value must not be negative”.
C.the code will not compile.
D.None of these.


9:
Which is the most appropriate code snippet that can be inserted at line 18 in the following code?

(Assume that the code is compiled and run with assertions enabled)

1. import java.util.*;

2.

3. public class AssertTest

4. {

5. private HashMap cctld;

6.

7. public AssertTest()

8. {

9. cctld = new HashMap();

10. cctld.put("in", "India");

11. cctld.put("uk", "United Kingdom");

12. cctld.put("au", "Australia");

13. // more code...

14. }

15. // other methods ....

16. public String getCountry(String countryCode)

17. {

18. // What should be inserted here?

19. String country = (String)cctld.get(countryCode);

20. return country;

21. }

22. }
A.assert countryCode != null;
B.assert countryCode != null : "Country code can not be null" ;
C.assert cctld != null : "No country code data is available";
D.assert cctld : "No country code data is available";


10:
Give this class outline:
class Example{
private int x;
//rest of class body…
}
Assuming that x invoked by the code java Example, which statement can made x be directly accessible in main() method of Example.java?
A.Change private int x to public int x
B.change private int x to static int x
C.Change private int x to protected int x
D.change private int x to final int x


11:
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)


12:
给出下面的代码片断。。。下面的哪些陈述为错误的?
1) public void create() {
2) Vector myVect;
3) myVect = new Vector();
4) }
A.第二行的声明不会为变量myVect分配内存空间。
B.第二行语句创建一个Vector类对象。
C.第三行语句创建一个Vector类对象。
D.第三行语句为一个Vector类对象分配内存空间


13:以下的C程序代码片段运行后C和d的值分别是多少
Int a =1,b =2;
Int c,d;
c =(a&b)&&a;
d =(a&&b)&a;

A.0,0
B.0,1
C.1,0
D.1,1


14:
下述程序代码中有语法错误的行是( )。
int i,ia[10],ib[10]; /*第一行*/
for (i=0;i<=9;i++) /*第2行*/
ia[i]=0; /*第3行*/
ib=ia; /*第4行*/
A.第1行
B.第2行
C.第3行
D.第4行


15:Which are not Java keywords?

A.TRUE
B.const
C.super
D.void
...全文
216 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
sciolist 2010-03-16
  • 打赏
  • 举报
回复
第一题的A,B 肯定不对...
hannover100 2010-03-16
  • 打赏
  • 举报
回复
什么考试题目啊
孤独剑客 2010-03-16
  • 打赏
  • 举报
回复
哪里的题目哦, 软通动力???
苍蝇①号 2010-03-16
  • 打赏
  • 举报
回复
7、A
8、C
9、AB
10、B
11、C
12、B
13、B
14、A
15、AB

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧