《SCJP考试题集》word版.doc

上传人:wux****ua 文档编号:9391828 上传时间:2020-04-05 格式:DOC 页数:81 大小:198.50KB
返回 下载 相关 举报
《SCJP考试题集》word版.doc_第1页
第1页 / 共81页
《SCJP考试题集》word版.doc_第2页
第2页 / 共81页
《SCJP考试题集》word版.doc_第3页
第3页 / 共81页
点击查看更多>>
资源描述
1. Which of the following range of short is correct? A. -27 - 27-1 B. 0 - 216-1 C. ?215 - 215-1 D. ?231 - 231-1 翻译 下面哪些是short型的取值范围。 答案 C 解析 短整型的数据类型的长度是16 bits,有符号。另外需要说明的是java中所有的整(Integral)数(包括byte,short,int,long)全是有符号的。 2. Which declarations of identifiers are legal? A. $persons B. TwoUsers C. *point D. this E. _endline 翻译 下面哪些是合法的标识符。 答案 A,B,E 解析 Java的标识符可以以一个Unicode字符,下滑线(_),美元符($)开始,后续字符可以是前面的符号和数字,没有长度限制,大小写敏感,不能是保留字。 3. Which statement of assigning a long type variable to a hexadecimal value is correct? A. long number = 345L; B. long number = 0345; C. long number = 0345L; D. long number = 0x345L 翻译 哪些是将一个十六进制值赋值给一个long型变量。 答案 D 解析 十六进制数以0x开头,long型数以L(大小写均可,一般使用大写,因为小写的l和数字1不易区分)。 4.Which of the following fragments might cause errors? A. String s = Gone with the wind; String t = good ; String k = s + t; B. String s = Gone with the wind; String t; t = s3 + one; C. String s = Gone with the wind; String standard = s.toUpperCase(); D. String s = home directory; String t = s - directory; 翻译 下面的哪些程序片断可能导致错误。 答案B,D 解析 A:String类型可以直接使用+进行连接运算。 B:String是一种Object,而不是简单的字符数组,不能使用下标运算符取其值的某个元素,错误。 C:toUpperCase()方法是String对象的一个方法,作用是将字符串的内容全部转换为大写并返回转换后的结果(String类型)。 D:String类型不能进行减(-)运算,错误。5. Which are syntactically valid statement at/ point x? class Person private int a; public int change(int m) return m; public class Teacher extends Person public int b; public static void main(String arg) Person p = new Person(); Teacher t = new Teacher(); int i; / point x A. i = m; B. i = b; C. i = p.a; D. i = p.change(30); E. i = t.b. 翻译 在/ point x处的哪些申明是句法上合法的。 答案D,E 解析 A:m没有被申明过,不能使用。 B:虽然b是类Teacher的public成员变量,但是在静态方法中不能使用类中的非静态成员。 C:a是类Person的private成员,在类外不能直接引用。 D:change(int m)方法是public方法,并且返回一个int型值,可以通过类的实例变量p引用并赋值给一个int型变量。 E:b是类Teacher的public成员变量,且是int型,可以通过类的实例变量t引用并赋值给一个int型变量。 6. Which layout manager is used when the frame is resized the buttonss position in the Frame might be changed? A. BorderLayout B. FlowLayout C. CardLayout D. GridLayout 翻译 当Frame的大小被改变时Frame中的按钮的位置可能被改变时使用的哪一个布局管理器。 答案 B 解析 A:该布局管理器将容器划分为五个部分,容器大小的改变不会影响其中的组件的位置而是影响他们的大小。 B:该布局管理器根据放入其中的组件的最合适大小调整组件的位置,根据组件放入的顺序安排,一行不能容纳时放入下一行,因此容器的大小改变可能改变组件的位置。 C:该布局管理器显示放入该容器的当前页中的组件,一次显示一个,容器大小的改变不能影响其中组件的位置。 D:该布局管理器将容器划分为固定的网格,组件加入后占据一个单元,各组件的相对位置不会因为容器的大小变化而变化,改变的只是组件的大小。7. Given the following code fragment: 1) public void create() 2) Vector myVect; 3) myVect = new Vector(); 4) Which of the following statements are true? A. The declaration on line 2 does not allocate memory space for the variable myVect. B. The declaration on line 2 allocates memory space for a reference to a Vector object. C. The statement on line 2 creates an object of class Vector. D. The statement on line 3 creates an object of class Vector. E. The statement on line 3 allocates memory space for an object of class Vector 翻译 给出下面的代码片断。下面的哪些陈述为true(真)? A. 第二行的声明不会为变量myVect分配内存空间。 B. 第二行的声明分配一个到Vector对象的引用的内存空间。 C. 第二行语句创建一个Vector类对象。 D. 第三行语句创建一个Vector类对象。 E. 第三行语句为一个Vector类对象分配内存空间。 答案A,D,E 解析SL-275中指出:要为一个新对象分配空间必须执行new Xxx()调用,new调用执行以下 的操作: 1 为新对象分配空间并将其成员初始化为0或者null。 2 执行类体中的初始化。(例如在类中有一个成员声明int a=10;在第一步后a=0 ,执行到第二步后a=10) 3 执行构造函数。 4 变量被分配为一个到内存堆中的新对象的引用。8. Which of the following answer is correct to express the value 8 in octal number? A. 010 B. 0x10 C. 08 D. 0x8 翻译 下面的哪些答案可以用以表示八进制值8。 答案 A 解析 八进制值以0开头,以0x开头的为十六进制值,八进制中不能出现数字8,最大只有7。 9. Which are not Java keywords? A. TRUE B. sizeof C. const D. super E. void 翻译 哪些不是Java关键字。 答案A,B 解析 A: 不是,Java中有true,但是这也不是关键字而是字面量(literal)。 B: 不是,Java中不需要这个操作符,所有的类型(原始类型)的大小都是固定的。 C、D、E都是,需要说明的是const是java中未被使用的关键字。10. Which of the following statements are true? A. The equals() method determines if reference values refer to the same object. B. The = operator determines if the contents and type of two separate objects match. C. The equals() method returns true only when the contents of two objects match. D. The class File overrides equals() to return true if the contents and type of two separate objects match. 翻译 下面的哪些叙述为真。A. equals()方法判定引用值是否指向同一对象。 B. = 操作符判定两个分立的对象的内容和类型是否一致。 C. equals()方法只有在两个对象的内容一致时返回true。 D. 类File重写方法equals()在两个分立的对象的内容和类型一致时返回true。 答案A,D 解析 严格来说这个问题的答案是不确定的,因为equals()方法是可以被重载的,但是按照java语言的本意来说:如果没有重写(override)新类的 equals(),则该方法和 = 操作符一样在两个变量指向同一对象时返回真,但是java推荐的是使用equals()方法来判断两个对象的内容是否一样,就像String类的 equals()方法所做的那样:判定两个String对象的内容是否相同,而=操作符返回true的唯一条件是两个变量指向同一对象。从这个意义上来 说选择给定的答案。从更严格的意义来说正确答案应该只有d。11. Which statements about inheritance are true? A. In Java programming language only allows single inheritance. B. In Java programming language allows a class to implement only one interface. C. In Java programming language a class cannot extend a class and implement a interface together. D. In Java programming language single inheritance makes code more reliable. 翻译 下面关于继承的哪些叙述是正确的。 A 在java中只允许单一继承。 B 在java中一个类只能实现一个接口。 C 在java中一个类不能同时继承一个类和实现一个接口。 D java的单一继承使代码更可靠。 答案A,D 解析 在java中一个类只能有一个直接父类,但是可以实现多个接口,在继承的同时可以实现接口,之所以取消多继承的原因是多继承使得代码产生很多问题,而使用单一继承则可以使代码更可靠。 12. 1) class Person 2) public void printValue(int i, int j) /*/ 3) public void printValue(int i)/*.*/ 4) 5) public class Teacher extends Person 6) public void printValue() /*.*/ 7) public void printValue(int i) /*.*/ 8) public static void main(String args) 9) Person t = new Teacher(); 10) t.printValue(10); 11) 12) Which method will the statement on line 10 call? A. on line 2 B. on line 3 C. on line 6 D. on line 7 翻译 第十行的声明将调用哪些方法。 答案 D 解析 变量t是一个Person对象,但是它是用Teacher实例化的,这个问题涉及到java的编译时多态和运行时多态的问题,就编译时多态来说,t实际上 是一个Person类,这涉及到类型的自动转换(将一个子类的实例赋值给一个父类的变量是不用进行强制类型转换,反之则需要进行强制类型转换,而且被赋值 的变量实际上应该是一个子类的对象),如果对t调用了子类中新增的方法则造成编译时错误编译将不能通过,而在运行时,运行时系统将根据t实际指向的类型调 用对应的方法,对于本例来说,t.print(10)将调用t实际指向的Teacher类的对应方法。在java中,可以用一个子类的实例实例化父类的一 个变量,而变量在编译时是一个父类实例,在运行时可能是一个子类实例。13. Which are not Java primitive types? A. short B. Boolean C. unit D. float 翻译 下面哪些不是java的原始数据类型。 答案B,C 解析 Java的原始数据类型一共就八个,分别是:byte,short,int,long,boolean,char,float,double。注意这些是 大小写敏感的,而Boolean是booelan的封装类(wrapper class)。 14. Use the operators , which statements are true? A. 0000 0100 0000 0000 0000 0000 0000 00005 gives 1000 0000 0000 0000 0000 0000 0000 0000 B. 0000 0100 0000 0000 0000 0000 0000 00005 gives 1111 1110 0000 0000 0000 0000 0000 0000 D. 1100 0000 0000 0000 0000 0000 0000 00005 gives 0000 0110 0000 0000 0000 0000 0000 0000 翻译 使用操作符的哪些陈述是对的。 答案A,C 解析 Java的移位操作符一共有三种,分别是”,”,” 32的结果是a而不是0,同理,对long型数是对右操作数取64的模,a64=a;还有一点需要注意的是移位操作符” ”只对int型和long型有效,对byte或者short的操作将导致自动类型转换,而且是带符号的。 15. Which of the following range of int is correct? A. -27 - 27-1 B. 0 - 232-1 C. ?215 - 215-1 D. ?231 - 231-1 翻译 int的取值范围是哪个。 答案 D 解析 int型是32位的。参看第一题的论述。 16. Which keyword should be used to enable interaction with the lock of an object? The flag allows exclusive access to that object. A. transient B. synchronized C. serialize D. static 翻译 下面的哪些关键字通常用来对对象的加锁,该标记使得对对象的访问是排他的 答案 B 解析 由于java是多线程的语言,多个线程可以”同时”访问同一数据区,而在处理某些数据时不希望其它的线程修改那些数据的值或者某些操作是不可打断的,要做到这个,可以使用synchronized关键字声明这一点。17. Which is the return type of the method main()? A. int B. void C. boolean D. static 翻译 main()方法的返回类型是什么? 答案 B 解析 在java中,程序运行的入口就是main()方法,它必须是这样的形式:public static void main(String args)。但是严格来讲这个题目的答案还可以加上a和c,因为并没有限定是程序入口的main()方法,而main()方法是可以重载的。一般意义 上的main()当然就是指我们刚开始所说的main()方法了。18. Given the following code: if (x0) System.out.println(first); else if (x-3) System.out.println(second); else System.out.println(third); Which range of x value would print the string second? A. x 0 B. x -3 C. x = -3 D. x -3 翻译 给出下面的代码: x的取值在什么范围内时将打印字符串second。 答案 D 解析 x0时打印first,x-3&x=0时打印second,x 10 ) public static void main(String arg) int i=10; Test t= new Test(); t.printValue(i); Which will be output? A. The value is 8 B. The value is 9 C. The value is 10 D. The value is 11 (c) 题目:给出下面的代码: 输出将是什么? 此题考察的是do while循环和 - 操作符的知识,dowhile最少被执行一次,在执行完do中的内容后判断while中的条件是否为true,如果为true的话就再执行do中的内 容,然后再进行判断,以此类推直到while的判断为false时退出循环执行循环后面的内容,而?操作符的规则是在变量右边的 - 将先进行运算,然后才是使变量的值减一,而在变量左边的是先将变量的值减一再运算。 26、Which of the following statements about declaration are true? A. Declaration of primitive types such as boolean, byte and so on does not allocate memory space for the variable. B. Declaration of primitive types such as boolean, byte and so on allocates memory space for the variable. C. Declaration of nonprimitive types such as String, Vector and so on does not allocate memory space for the object. D. Declaration of nonprimitive types such as String, Vector ans so on allocates memory space for the object. (ad) 题目:下面的有关声明的哪些叙述是对的。 A. 对原始数据类型例如boolean,byte的变量的声明不会为该变量分配内存空间。 B. 对原始数据类型例如boolean,byte的变量的声明将为之分配内存空间。 C. 非原始数据类型例如String,Vector的变量的声明不会为该对象分配内存。 D. 非原始数据类型例如String,Vector的变量的声明会为该对象分配内存。 对原始数据类型的变量的声明将为之分配内存并赋予一个缺省值,参见23题的叙述,而非原始数据类型的变量必须用new Xxxx()分配内存及初始化。但是严格来讲此题的答案有待确定,因为只有原始类型的实例变量和类变量的声明在类对象被创建/类被加载时完成内存的自动分 配,而原始类型的局部变量必须显式初始化,从这点来看原始类型的局部变量没有被自动分配内存,SL275中只提出了非原始数据类型的变量必须使用new Xxxx()完成内存的分配而没有指出原始数据类型的变量是否在声明时即自动进行内存分配,而从局部变量不能在显式初始化前使用这点来看在声明时没有进行 内存分配。因此答案a的正确性还有待官方的确定。27、In the Java API documentation which sections are included in a class document? A. The description of the class and its purpose B. A list of methods in its super class C. A list of member variable D. The class hierarchy (acd) 题目:在Java API文档中下面的哪些部分被包括在内 A. 类及用途的描述 B. 父类的方法的列表 C. 成员变量的列表 D. 类层次 类文档的内容主要是:类层次、类及用途描述、成员变量列表、构造方法列表、成员方法列表、从类层次上继承的方法列表、成员变量的详细说明、构造方法详细说明、成员方法详细说明。 28、Given the following code: 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) 题目:下面有关变量及其作用域的陈述哪些是对的。 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可以达到要求。31Given 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)的“与”应该是&,而在执行“与”操作的时候,如果第一个条件为false,那么第二个条件判断运算是不做的,但是 这里是位逻辑操作符(bitwise logical operator)的“与”,在进行这个运算时,无论第一个条件的结果是什么都会执行第二个的运算,因此,假设str=null,那么第5句的 str.length()就会导致NullPointerException,因此本题的错误在于此。 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 int10; public static void main(String a) System.out.println(arr1;) 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型数组是类对象,它在类被加载时完成初始化,在前面题目中已经有叙述,由于是原始数据类型int,其初始值为0。34、Given the following code: public class Person int arr = new int10; public static void main(String a) System.out.println(arr1); 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,而普通方法有。 35、public class Parent public int addValue( int a, int b) int s; s = a+b; return s; class Child extends Parent Which methods can be added into class Child? A. int addValue( int a, int b )/ do something. B. public void addValue ()/ do something. C. public int addValue( int a )/ do something. D. public int addValue( int a, int b )throws MyException /do something. (bc) 题目:哪些方法可以加入类Child中。 此题涉及方法重载(overload),方法重写(override)以及类派生时方法重写的规则。方法重载的规则是:一、参数列表必须不同,个数的不同 完全可以,如果个数相同则参数类型的不同不能引起歧意,例如int 和long,float和double就不能作为唯一的类型不同;二、返回值可以不同,但是不能是重载时唯一的不同点(这点和c+中不同,c+中返回 类型必须一致)。方法重写发生在类继承时,子类可以重写一个父类中已有的方法,必须在返回
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 图纸专区 > 考试试卷


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!