JAVA认证历年真题:SCJP考试真题和解析(1)
来源:优易学  2011-9-22 19:41:05   【优易学:中国教育考试门户网】   资料下载   IT书店

 

11.Given the following class definition:
class A{
protected int i;
A(int i){
this.i=i;
}
}
which of the following would be a valid inner class for this class?
Select all valid answers:
A. class B{
}
B. class B extends A{
}
C. class B extends A{
B(){System.out.println(“i=”+i);}
}
D. class B{
class A{}
}
E. class A{}

11。A
此题考查内部类及关键字“super”的用法。内部类不能与外部类同名。另外,当B继承A时,A中的构造函数是带参数的,B中缺省构造函数的函数体为空;而JAVA编译器会为空构造函数体自动添加语句“super();”调用父类构造函数,更进一步是调用父类的参数为空的构造函数。而父类中没有参数为空的构造函数。
12. Which modifier should be applied to a method for the lock of object this to be obtained prior to excution any of the method body?
A. synchronized
B. abstract
C. final
D. static
E. public

12。A
此关键字可以在两个线程同时试图访问某一数据时避免数据毁损。
13. The following code is entire contents of a file called Example.java,causes precisely one error during compilation:
1) class SubClass extends BaseClass{
2) }
3) class BaseClass(){
4) String str;
5) public BaseClass(){
6) System.out.println(“ok”);}
7) public BaseClass(String s){
8) str=s;}}
9) public class Example{
10) public void method(){
11) SubClass s=new SubClass(“hello”);
12) BaseClass b=new BaseClass(“world”);
13) }
14) }

Which line would be cause the error?
A. 9 B. 10 C. 11 D.12

13。C
当一个类中未显式定义构造函数时,缺省的构造函数是以类名为函数名,参数为空,函数体为空。虽然父类中的某一构造函数有字符串参数s,但是子类继承父类时并不继承构造函数,所以它只能使用缺省构造函数。故在第11行出错。

14. Which statement is correctly declare a variable a which is suitable for refering to an array of 50 string empty object?
A. String [] a
B. String a[]
C. char a[][]
D. String a[50]
F. Object a[50]

14。A、B
注意,题中问的是如何正确声明一个一维数组,并非实例化或者初始化数组
15. Give the following java source fragement:
//point x
public class Interesting{
//do something
}
Which statement is correctly Java syntax at point x?
A. import java.awt.*;

B.package mypackage
C. static int PI=3.14
D. public class MyClass{//do other thing…} E. class MyClass{//do something…}

15。A、E
X处可以是一个输入,包的定义,类的定义。由于常量或变量的声明只能在类中或方法中,故不能选择C;由于在一个文件中只能有一个public类,故不能选择D。
16. 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

16。B
静态方法除了自己的参数外只能直接访问静态成员。访问非静态成员,必须先实例化本类的一个实例,再用实例名点取。
17. the piece of preliminary analsis work describes a class that will be used frequently in many unrelated parts of a project
“The polygon object is a drawable, A polygon has vertex information stored in a vector, a color, length and width.”
Which Data type would be used?
A. Vector
B. int
C. String
D. Color
E. Date

17。A、B、D
polygon的顶点信息存放在Vector类型的对象内部,color定义为Color,length和width定义为int。
注意,这是考试中常见的题型。
18. 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
18。C
此题考点是高级访问控制。请考生查阅高级访问控制说明表格。

上一页  [1] [2] [3] [4] [5] [6] [7] 下一页

责任编辑:小草

文章搜索:
 相关文章
热点资讯
资讯快报
热门课程培训