选择题
1:下面关于变量及其范围的陈述哪些是错的。
A.实例变量是类的成员变量。
B.实例变量用关键字static声明。
C.在方法中定义的局部变量在该方法被执行时创建
D.局部变量在使用前必须被初始化。
2:
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
3:
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
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:使用 JDBC 可以做到的是
A.把二进制代码传送到任何关系数据库中
B.把 Java 源代码传送到任何关系数据库中
C.把表单信息传送到任何关系数据库中
D.很容易地把 SQL 语句传送到任何关系数据库中
6:鉴于Java的特点,它最适合的计算环境是
A.并行计算环境
B.分布式计算环境
C.高强度计算环境
D.开放式计算环境
7:在下述选项时,没有构成死循环的程序是
A.int i=100 while (1) { i=i%100+1; if (i>100) break; }
B.for (;;);
C.int k=1000; do { ++k; }while(k>=10000);
D.int s=36; while (s);–s;
8: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
9:
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
10: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++;
11:
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″.
12:
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
13:
下述程序代码中有语法错误的行是(
)。
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行
14:
Select valid identifier of Java:
A.%passwd
B.3d_game
C.$charge
D.this
15:
What will be the result of executing the following code
public static void main(String args[])
{
char digit = ‘a’;
for (int i = 0; i < 10; i++)
{
switch (digit)
{
case ‘x’ :
{
int j = 0;
System.out.println(j);
}
default :
{
int j = 100;
System.out.println(j);
}
}
}
int i = j;
System.out.println(i);
}
Choices:
A.100 will be printed 11 times.
B.The code will not compile because the variable i cannot be declared twice within the main() method.
C.The code will not compile because the variable j cannot be declared twice within the switch statement.
D.None of these.
16:Which are not Java keywords
A.TRUE
B.const
C.super
D.void
简答题
17:C/C++源代码中,检查花括弧“(“与 “)“,“{“与“}”)是否匹配,若不匹配,则输出不匹配花括弧所在的行与列。
18:STRING与STRINGBUFFER的区别。
19:There are two int variables: a and b, don’t use “if”, “ :”, “switch”or other judgement statements, find out the biggest one of the two numbers.
20:Collection 和 Collections的区别。
21:写一个程序,读入一个 3 × 3 的矩阵,输出它的转置。(注:转置是将原矩阵的行列互换)
22:JAVA SERVLET API中forward() 与redirect()的区别?
23:四种会话跟踪技术。
24:两个数相乘,小数点后位数没有限制,请写一个高精度算法。
25:Java的国际化