资源描述
选择题
1:
1. What is the result when you compile and run the following code?
2.
3. public class Test
4.
5. {
6.
7. public void method()
8.
9. {
10.
11. for(int i = 0; i < 3; i++)
12.
13. {
14.
15. System.out.print(i);
16.
17. }
18.
19. System.out.print(i);
20.
21. }
22.
23. }
24.
25. Choices:
What is the result when you compile and run the following code?
public class Test
{
public void method()
{
for(int i = 0; i < 3; i++)
{
System.out.print(i);
}
System.out.print(i);
}
}
Choices:
A.0122
B.0123
C.Compilation error
D.None of these
2:关于垃圾收集的哪些叙述是对的。
A.程序开发者必须自己创建一个线程进行内存释放的工作。
B.垃圾收集将检查并释放不再使用的内存。
C.垃圾收集允许程序开发者明确指定并立即释放该内存。
D.垃圾收集能够在期望的时间释放被java对象使用的内存。
3:在软件生命周期中,下列哪个说法是不准确的?
A.软件生命周期分为计划、开发和运行三个阶段
B.在计划阶段要进行问题焉醛和需求分析
C.在开发后期要进行编写代码和软件测试
D.在运行阶段主要是进行软件维护
4:
1. What will be the result of executing the following code?
2.
3. // Filename; SuperclassX.java
4.
5. package packageX;
6.
7. public class SuperclassX
8.
9. {
10.
11. protected void superclassMethodX()
12.
13. {
14.
15. }
16.
17. int superclassVarX;
18.
19. }
20.
21.
22.
23. // Filename SubclassY.java
24.
25. 1.package packageX.packageY;
26.
27. 2.
28.
29. 3.public class SubclassY extends SuperclassX
30.
31. 4.{
32.
33. 5.SuperclassX objX = new SubclassY();
34.
35. 6.SubclassY objY = new SubclassY();
36.
37. 7.void subclassMethodY()
38.
39. 8.{
40.
41. 9.objY.superclassMethodX();
42.
43. 10.int i;
44.
45. 11.i = objY.superclassVarX;
46.
47. 12.}
48.
49. 13.}
50.
51. Choices:
What will be the result of executing the following code?
// Filename; SuperclassX.java
package packageX;
public class SuperclassX
{
protected void superclassMethodX()
{
}
int superclassVarX;
}
// Filename SubclassY.java
1.package packageX.packageY;
2.
3.public class SubclassY extends SuperclassX
4.{
5.SuperclassX objX = new SubclassY();
6.SubclassY objY = new SubclassY();
7.void subclassMethodY()
8.{
9.objY.superclassMethodX();
10.int i;
11.i = objY.superclassVarX;
12.}
13.}
Choices:
A.Compilation error at line 5
B.Compilation error at line 9
C.Runtime exception at line 11
D.None of these
5:
1. 给出下面的代码片断。。。下面的哪些陈述为错误的?
2. 1) public void create() {
3. 2) Vector myVect;
4. 3) myVect = new Vector();
5. 4) }
给出下面的代码片断。。。下面的哪些陈述为错误的?
1) public void create() {
2) Vector myVect;
3) myVect = new Vector();
4) }
A.第二行的声明不会为变量myVect分配内存空间。
B.第二行语句创建一个Vector类对象。
C.第三行语句创建一个Vector类对象。
D.第三行语句为一个Vector类对象分配内存空间
6:Which code fragments would correctly identify the number of arguments passed via command line to a Java application, exclude the name of the class that is being invoke.
A.int count = args.length;
B.int count = args.length-1;
C.int count=0; while(args[count]!=null) count++;
D.int count=0;while (!(args[count].equals(“”))) count++;
7:Which is the main() method return of a application?
A.String
B.byte
C.char
D.void
8:Use the operator “>>” and “>>>”. Which statement is true?
A.1010 0000 0000 0000 0000 0000 0000 0000 >> 4 give 0000 1010 0000 0000 0000 0000 0000 0000
B.1010 0000 0000 0000 0000 0000 0000 0000 >> 4 give 1111 1010 0000 0000 0000 0000 0000 0000
C.1010 0000 0000 0000 0000 0000 0000 0000 >>> 4 give 0000 0000 0000 0000 0000 0000 0000 0000
D.1010 0000 0000 0000 0000 0000 0000 0000 >>> 4 give 1111 1010 0000 0000 0000 0000 0000 0000
9: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
10:
1. public class OuterClass {
2. private double d1 = 1.0;
3. //insert code here
4. }
5. You need to insert an inner class declaration at line 3. Which two inner class declarations are
6. 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;} }
11:
1. public class X{
2.
3. public Object m(){
4.
5. Object o = new Float(3.14F);//line 3
6.
7. Object [] oa = new Object[1];//line 4
8.
9. oa[0] = o;//line 5
10.
11. o=null;//line 6
12.
13. return oa[0];//line 7
14.
15. }
16.
17. }
18. 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
12:Which statements about Java code security are not true?
A.The bytecode verifier loads all classes needed for the execution of a program.
B.Executing code is performed by the runtime interpreter.
C.At runtime the bytecodes are loaded, checked and run in an interpreter.
D.The class loader adds security by separating the namespaces for the classes of the local file system from those imported from network sources.
13:使用 JDBC 可以做到的是
A.把二进制代码传送到任何关系数据库中
B.把 Java 源代码传送到任何关系数据库中
C.把表单信息传送到任何关系数据库中
D.很容易地把 SQL 语句传送到任何关系数据库中
14:
1. Give the following code:
2. public class Example{
3. public static void main(String args[] ){
4. int l=0;
5. do{
6. System.out.println(“Doing it for l is:”+l);
7. }while(--l>0)
8. System.out.println(“Finish”);
9. }
10. }
11. Which well be output:
Give the following code:
public class Example{
public static void main(String args[] ){
int l=0;
do{
System.out.println(“Doing it for l is:”+l);
}while(--l>0)
System.out.println(“Finish”);
}
}
Which well be output:
A.Doing it for l is 3
B.Doing it for l is 1
C.Doing it for l is 2
D.Doing it for l is 0
15:
1. What will happen when you attempt to compile and run the following code?
2.
3. int Output = 10;
4.
5. boolean b1 = false;
6.
7. if((b1 == true) && ((Output += 10) == 20))
8.
9. {
10.
11. System.out.println("We are equal " + Output);
12.
13. }
14.
15. else
16.
17. {
18.
19. System.out.println("Not equal! " + Output);
20.
21. }
22.
23. Choices:
What will happen when you attempt to compile and run the following code?
int Output = 10;
boolean b1 = false;
if((b1 == true) && ((Output += 10) == 20))
{
System.out.println("We are equal " + Output);
}
else
{
System.out.println("Not equal! " + Output);
}
Choices:
A.Compilation error, attempting to perform binary comparison on logical data type
B.Compilation and output of "We are equal 10".
C.Compilation and output of "Not equal! 20".
D.Compilation and output of "Not equal! 10".
16:设有变量说明语句int a=1,b=0;
则执行以下程序段的输出结果为( )。
switch (a)
{
case 1:
switch (b)
{
case 0:printf("**0**");break;
case 1:printf("**1**");break;
}
case 2:printf("**2**");break;
}
printf("\n");
A.**0**
B.**0****2**
C.**0****1****2**
D.有语法错误
简答题
17:String是最基本的数据类型吗?
18:数组a[N],存放了1至N-1个数,其中某个数重复一次。写一个函数,找出被重复的数字.时间复杂度必须为o(N)函数原型:int do_dup(int a[],int N)
19:用 100 元钱买 100 支笔,其中钢笔 3 元 / 支,圆珠笔 2 元 / 支,铅笔 0.5 元 / 支,问钢笔、圆珠笔和铅笔可以各买多少支 ?
20:如何现实servlet的单线程模式?
21:有一个整数n,写一个函数f(n),返回0到n之间出现的\"1\"的个数。比如f(13)=6,现在f(1)=1,问下一个最大的f(n)=n的n是什么?
22:自己随意构造一个用户类(UserRecord)。然后编写一个程序,创建十个UserRecord对象,将它们保存到一个文件中,然后再从该文件中恢复该组对象。
23:如何启动时不需输入用户名与密码?
24:巧排数字,将1,2,...,19,20这20个数字排成一排,使得相邻的两个数字之和为一个素数,且首尾两数字之和也为一个素数。编程打印出所有的排法。
25:介绍在Jsp中如何使用JavaBeans。
展开阅读全文