SCJP考试真题和解析[2](3)
添加时间: 2007-9-23 1:41:24 作者: JAVA题库 阅读次数:74 来源: http://www.d9soft.com
1) public void modify() {
2) int i, j, k;
3) i = 100;
4) while ( i > 0 ) {
5) j = i * 2;
6) System.out.println (" The value of j is " + j );
7) k = k + 1;
8) i--;
9) }
10) }
Which line might cause an error during compilation?
A. line 4
B. line 6
C. line 7
D. line 8
(c)
题目:给出下面的代码:
…
哪些行在编译时可能产生错误。
这个问题在前面有关变量的类型及其作用域的问题中讨论过,局部变量在使用前必须显式初始化,而代码中的变量k在使用前没有。
29、Which of the following statements about variables and scope are true?
A. Local variables defined inside a method are destroyed when the method is exited.
B. Local variables are also called automatic variables.
C. Variables defined outside a method are created when the object is constructed.
D. A method parameter variable continues to exist for as long as the object is needed in which the method is defined.
(abc)
题目:下面有关变量及其作用域的陈述哪些是对摹?BR> A. 在方法里面定义的局部变量在方法退出的时候被撤销。
B. 局部变量也叫自动变量。
C. 在方法外面定义的变量(译注:即实例变量)在对象被构造时创建。
D. 在方法中定义的方法的参变量只要该对象被需要就一直存在。
本题还是讨论变量的类型及作用域,参看前面的叙述。
30、A class design requires that a member variable cannot be accessible directly outside the class. Which modifier should be used to obtain the access control?
A. public
B. no modifier
C. protected
D. private
(d)
题目:类的设计要求它的某个成员变量不能被外部类直接访问。应该使用下面的哪些修饰符获得需要的访问控制。
这个在前面也有叙述,java有四种访问类型,分别为:public,protected,default,private,其中public变量可以被所有的外部类访问,而pretected的可以被同一个包及该类的子类访问,default即没有任何修饰符的变量可以被同一个包中的类访问,而private变量只能在被该类内部被访问。题目中的外部类应该理解为除该类自身的所有其它类,因此只有使用private可以达到要求。
31、Given the following code fragment:
1) String str = null;
2) if ((str != null) && (str.length() > 10)) {
3) System.out.println("more than 10");
4) }
5) else if ((str != null) & (str.length() < 5)) {
6) System.out.println("less than 5");
7) }
8) else { System.out.println("end"); }
Which line will cause error?
A. line 1
B. line 2
C. line 5
D. line 8
(c)
题目:给出下面的代码片断:
…
哪些行将导致错误。
此题需要将代码仔细看清楚,查询没有逻辑错误,if …else的使用没有问题,也没有拼写错误,错误在于第5行的“与”操作符的使用,逻辑操作符(logical operator)的“与”应该是&&,而&是位逻辑操作符(bitwise logical operator)的“与”,使用的对象不一样,逻辑操作符的“与”的左右操作数都应该是布尔型(logical boolan)的值,而位逻辑操作符的左右操作数都是整型(integral)值。
32、Which statements about Java code security are 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.
(bcd)
题目:下面有关java代码 安全 性的叙述哪些是对的。
A. 字节码校验器加载查询执行需要的所有类。
B. 运行时解释器执行代码。
C. 在运行时,字节码被加载,验证然后在解释器里面运行。
D. 类加载器通过分离本机文件系统的类和从 网络 导入的类增加 安全 性。
SL275中描述的 Java 程序运行的过程是这样的:类加载器(class loader)加载程序运行所需要的所有类,它通过区分本机文件系统的类和网络系统导入的类增加安全性,这可以限制任何的特洛伊木马程序,因为本机类总是先被加载,一旦所有的类被加载完,执行文件的内存划分就固定了,在这个时候特定的内存地址被分配给对应的符号引用,查找表(lookuo table)也被建立,由于内存划分发生在运行时,解释器在受限制的代码区增加保护防止未授权的访问;然后字节码校验器(byte code verifier)进行校验,主要执行下面的 检查 :类符合JVM规范的类文件格式,没有违反访问限制,代码没有造成堆栈的上溢或者下溢,所有操作代码的参数类型都是正确的,没有非法的数据类型转换(例如将整型数转换成对象类型)发生;校验通过的字节码被解释器(interpreter)执行,解释器在必要时通过运行时系统执行对底层硬件的合适调用。后三个答案是SL275中的原话。
33、Given the following code:
public class Person{
static int arr[] = new int[10];
public static void main(String a[]) {
System.out.println(arr[1];)
}
}
Which statement is correct?
A. When compilation some error will occur.
B. It is correct when compilation but will cause error when running.
C. The output is zero.
D. The output is null.
(c)
题目:给出下面的代码:
…
那个叙述是对的。
A. 编译时将发生错误。
B. 编译时正确但是运行时出错。
C. 输出为0。
D. 输出为null
int型数组是类对象,它在类被加载蓖瓿沙跏蓟谇懊嫣饽恐幸丫行鹗觯捎谑窃际堇嘈蚷nt,其初始值为0。
34、Given the following code:
public class Person{
int arr[] = new int[10];
public static void main(String a[]) {
System.out.println(arr[1]);
}
}
Which statement is correct?
A. When compilation some error will occur.
B. It is correct when compilation but will cause error when running.
C. The output is zero.
D. The output is null.
(a)
给出下面的代码:
…
哪些叙述是对的。
A. 编译时出错。
B. 编译时正确而运行时出错。
C. 输出0。
D. 输出null。
实例变量在类的一个实例构造时完成初始化,而且在类的静态方法中不能直接访问类的非静态成员而只能访问类成员(像上题中一样),类的普通方法可以访问类的所有成员和方法,而静态方法只能访问类的静态成员和方法,因为静态方法属于类,而普通方法及成员变量属于类的实例,类方法(静态方法)不能使用属于某个不确定的类的实例的方法和变量,在静态方法里面没有隐含的this,而普通方法有。
A. The thread which is stopped by calling method stop()
B. The thread which is stopped by calling method sleep()
C. The thread which is stopped by calling method wait()
D. The thread which is stopped by calling method suspend()
(d)
题目:方法resume()负责恢复哪些线程的执行。
A. 通过调用stop()方法而停止的线程。
B. 通过调用sleep()方法而停止运行的线程。
C. 通过调用wait()方法而停止运行的线程。
D. 通过调用suspend()方法而停止运行的线程。
Thread的API文档中的说明是该方法恢复被挂起的(suspended)线程。该方法首先调用该线程的无参的checkAccess() 方法,这可能在当前线程上抛出SecurityException 异常,如果该线程是活着的(alive)但是被挂起(suspend),它被恢复并继续它的执行进程。
60、Given the following code:
1) public class Test {
2} int m, n;
3} public Test() {}
4} public Test(int a) { m=a; }
5} public static void main(String arg[]) {
6} Test t1,t2;
7} int j,k;
8} j=0; k=0;
9} t1=new Test();
10} t2=new Test(j,k);
11} }
12} }
Which line would cause one error during compilation?
A. line 3
B. line 5
C. line 6
D. line 10
(d)
题目:给出下面的代码:
…
在编译时哪行将导致一个错误。
第10行的声明调用一个带两个参数的Test的构造方法,而该类没有这样的构造方法。
上一篇文章: SCJP考试真题和解析[2](2) 下一篇文章: Java认证模拟题及分析(3)
相关文章:

](/d9soft/images/logo_1.gif)