SCJP认证考试题库3

合集下载

全国青少年机器人技术等级考试三级(编程)模拟试卷及答题解析03

全国青少年机器人技术等级考试三级(编程)模拟试卷及答题解析03

全国青少年机器人技术等级考试三级(编程)模拟试题三一、单选题(共30 题,每题2 分)1、int定义的数据类型为(C)A)字符型B)单精度浮点型C)整型数据D)双精度浮点型2、三极管的伏安特性是指其(A )A.输入与输出特性B.输出特性C.输入特性D.以上选项都不对3、电压表、电流表、小灯泡在电路中的符号依次为(C)。

A. B.C. D.4、下面可以实现延时0.5秒的是(D )A. B.C. D.5、此模块的作用是(A )A.延时10秒钟B.延时10毫秒C.蜂鸣器发出声音10秒钟D.电机转动10毫秒6、如图所示电路中哪个电路是正确的(A)A. B. C. D.7、执行如下语句,串口监视器的显示值是(C)A,255 B 1 C 0 D 2568、或门电路输入0和1,会输出(D)A. 1B.0C.先输出1后输出0D.先输出0后输出19、下列常见的物品中能被磁铁吸引的是(B )A.橡皮B.铁定C.铜钥匙D.塑料尺10、楼道中的灯只有光线暗且有声音的时候才会亮,那么光线暗和有声音的逻辑关系是(B )A.逻辑或B.逻辑与C.以上选项都不对D.逻辑非11、通常情况下下列物体属于绝缘体的是(A)A.橡胶棒B.铁丝C.人体D.盐水12、已知以下语句执行后a、b、c的值是(C )A)a=10,b=30,c=20 B)a=20,b=30,c=10 C)a=10,b=20,c=30 D)a=20,b=30,c=1013、在程序运行过程中其值不能被改变的量为?(B)A.变量B.常量C.只能是变量不能是常量D.常量、变量都可以14、C语言中一条命令结束的符号为( D )A、“//”B、“。

”C、“.”D、“;”15、通过人体最大安全电压为(D )A.380VB.1.5VC.220VD.36V16、串联电路中保持电路的两端电压不变,加大电路中的电阻的阻值,则电路中的电流如何(B )A.不变B.变小C.变大D.不确定17、运算符逻辑或的符号为(D )A.“&&”B.“!”C.“&”D.“||”18、二极管之所以被称为半导体是因为它具有什么特性(C )A.有两个引脚B.双向导电性C,单向导电性 D.导电性19、马路上的路灯总一起亮,一起灭,如果他们其中一盏灯的灯丝断了,其他灯仍正常发光,根据这些现象判断路灯是(B)A.可以是串联也可以是并联B.一定是并联C.一定是串联D. 不能确定是何种联系方式20、下列属于整形数据的是(A )A.123B.abcC.11.2D.6.23621、执行以下语句后x、y、z的值是( C )A)x=20,y=30,z=30 B)x=20,y=30,z=10 C)x=10,y=20,z=30 D)x=20,y=30,z=2022、二极管的导通条件是所给电压U要满足(C)A)U>0 B)U>截止电压C)U>导通电压D)U>击穿电压23、一个并联电路并联了3个灯泡,测得电源两边的电压为3V,则通过每个灯泡的电压为(A)A、3VB、1VC、6V24、关于电流和电源下列说法正确的是(B)A、电流是由电荷做无规则运动形成的B、在电源的外部,电流从电源的正极流向电源的负极C、电路中只要有电源就一定有电流D、金属导体中电流的方向与电子移动的方向相同25、下列说法正确的是(C)A、编程语言只有C语言一种B、机器人无程序也可正常运行C、算法就是为解决一个问题而采取的方法和步骤D、if语句结构属于顺序结构26、2017年战胜围棋选手柯洁的机器人名称是(A)A、B、C、D、27、三极管的电极不包括哪一个(C)A、发射极B、基极C、接收极D、集电极28、程序中的高电平一般用(C)来表示A、0或1B、0C、1D、以上选项都不对29、电压的单位是(D)A、安培B、欧姆C、法拉D、伏特30、下列四组物体中都属于绝缘体的是(B)A、水银铜丝铁块B、陶瓷于木塑料C、碳棒人体大地D、大地人体陶瓷二、多选题(共5题,每题4 分)31、二进制数据是由哪几个数码来表示的(B C)A、3B、1C、0D、232、常用的半导体制作材料有哪些(C D)A、铝B、铜C、锗D、硅33、根据日常生活现象,下列说法正确的是(A B C)A、楼道中的照明灯是由声控开关和光控开关共同控制的,只有在天暗并且有声音时才能亮,所以声控开关、光控开关及灯是串联的。

2023年9月GESP编程能力认证C++等级考试三级真题(含答案)

2023年9月GESP编程能力认证C++等级考试三级真题(含答案)

2023年9月GESP编程能力认证C++等级考试三级真题(含答案)一、单选题(每题2分,共30分)。

1.人们所使用的手机上安装的App通常指的是()。

A. 一款操作系统B. 一款应用软件C. 一种通话设备D. 以上都不对正确答案:B。

2.下列流程图的输出结果是?()。

A. 60B. 20C. 5D. 1正确答案:B。

3.已知大写字符 'A' 的ASCII编码的十六进制表示为0x41 ,则字符 'L' 的ASCII编码的十六进制表示为()。

A. 4AB. 4BC. 4CD. 52正确答案:C。

4.以下哪个不是C++语言中的运算符?()。

A. ~B. ~~C. <D. <<正确答案:B。

5.如果数组定义为long long array[] = {3, 5, 7, 2}; ,则数组array占用的字节数为()。

A. 32B. 16C. 8D. 4正确答案:A。

6.一个数组定义为double array[3]; ,则可合理访问这个数组的元素的下标最大为()。

A. 2B. 3C. 23D. 24正确答案:A。

7.以下数组定义,符合C++语言语法的是()。

A. double a[];B. double b[] = {1, 2.0, '3'};C. double c[3.0];D. double[] d = new double[3];正确答案:B。

8.下列关于进制的叙述,正确的是()。

A. 只有十进制和二进制能够用来表示小数,八进制和十六进制不可以。

B. 常用的进制包括二进制、八进制、十进制、十六进制,其他进制在日常生活中很少使用。

C. 对任意正整数,其二进制表示不会比它的十进制表示更短。

D. 正整数的八进制表示中,每一位可能出现的最大数字是8。

正确答案:C。

9.下列关于C++语言中数组的叙述,不正确的是()。

A. 可以定义0个元素的数组。

B. 不能定义 -1个元素的数组。

英文SCJP模拟题200道附答案

英文SCJP模拟题200道附答案

英文SCJP模拟题200道附答案,因为目录分隔符不正确。

3)执行此代码时,不会在硬盘上创建文件。

4)如果文件已经存在,运行时将引发异常。

5)代码无法编译,因为这不是文件类的有效构造函数。

问题7:关于随机访问文件类,下列哪项陈述是正确的?1)如果使用\模式创建时指定的文件不存在,则会引发IOException。

2)这个类有一个允许从硬盘上删除文件的方法。

3)可以将这个类与DataInputStream类结合使用。

4)当与\模式一起使用时,如果指定的文件不存在,它将在磁盘驱动器上创建。

5)有读和写主词的方法(例如,readInt(),writeInt(),等等)。

考虑下面这段代码,并从下面选择正确的语句。

1.字符串s =新字符串(\ 2 . s . replace(“d”、“q”);3.系统输出打印输入。

1)代码编译失败,在第2行报告了一个错误。

字符串是不可变的,因此replace()方法毫无意义。

2)代码编译正确,并显示文本\ 3)代码编译正确,并显示文本\4)代码编译,但是在执行第2行时会引发异常。

5)代码编译,但是在第3行抛出异常。

Q9下列哪个关键字可以应用到界面的变量或方法中。

1)静态2)私有3)同步4)受保护5)公共Q10真或假。

只有框架可以包含菜单栏或下拉菜单。

1)真2)假。

Q11考虑以下代码,选择正确的语句:1.甲级2.受保护的int方法(){ 3。

} 4。

} 5。

6.B类扩展了A{ 7。

int方法(){ 8。

} 9。

}1)代码无法编译,因为您不能重写一个比其父方法更私有的方法。

2)代码无法编译,因为方法()被声明为受保护的,因此对任何子类都不可用。

3)代码编译正确,但是在运行时抛出一个空指针异常。

4)代码无法编译。

但是,可以通过在第7行前加上访问限定符\来正确编译5)代码无法编译。

但是,可以通过在第7行前加上访问限定符\ Q12真或假来进行正确编译。

可抛出类是Java语言中所有异常的超类。

JAVA认证历年真题:SCJP认证套题解析(3)

JAVA认证历年真题:SCJP认证套题解析(3)

JAVA认证历年真题:SCJP认证套题解析(3)41、Which of the following statements are legal?A. long l = 4990;B. int i = 4L;C. float f = 1.1;D. double d = 34.4;E. double t = 0.9F.(ade)题目:下面的哪些声明是合法的。

此题的考点是数字的表示法和基本数据类型的类型自动转换,没有小数点的数字被认为是int型数,带有小数点的数被认为是double型的数,其它的使用在数字后面加一个字母表示数据类型,加l或者L是long型,加d或者D是double,加f或者F是float,可以将低精度的数字赋值给高精度的变量,反之则需要进行强制类型转换,例如将int,short,byte赋值给long 型时不需要显式的类型转换,反之,将long型数赋值给byte,short,int型时需要强制转换(int a=(int)123L;)。

42、public class Parent {int change() {…}}class Child extends Parent {}Which methods can be added into class Child?A. public int change(){}B. int chang(int i){}C. private int change(){}D. abstract int chang(){}(ab)题目:哪些方法可被加入类Child。

这个题目的问题在第35题中有详尽的叙述。

需要注意的是答案D的内容,子类可以重写父类的方法并将之声明为抽象方法,但是这引发的问题是类必须声明为抽象类,否则编译不能通过,而且抽象方法不能有方法体,也就是方法声明后面不能带上那两个大括号({}),这些D都不能满足。

43、class Parent {String one, two;public Parent(String a, String b){one = a;two = b;}public void print(){ System.out.println(one); }}public class Child extends Parent {public Child(String a, String b){super(a,b);}public void print(){System.out.println(one + " to " + two);}public static void main(String arg[]){Parent p = new Parent("south", "north");Parent t = new Child("east", "west");p.print();t.print();}}Which of the following is correct?A. Cause error during compilation.B. southeastC. south to northeast to westD. south to northeastE. southeast to west(e)题目:下面的哪些正确。

程序员英文考题

程序员英文考题

SCJP考试题310-025原题及解答1. Which statement are characteristics of the >> and >>> operators.A. >> performs a shiftB. >> performs a rotateC. >> performs a signed and >>> performs an unsigned shiftD. >> performs an unsigned and >>> performs a signed shiftE. >> should be used on integrals and >>> should be used on floating point typesC.2. Given the following declarationString s = "Example";Which are legal code?A. s >>> = 3;B. s[3] = "x";C. int i = s.length();D. String t = "For " + s;E. s = s + 10;CDE.3. Given the following declarationString s = "hello";Which are legal code?A. s >> = 2;B. char c = s[3];C. s += "there";D. int i = s.length();E. s = s + 3;CDE.4. Which statements are true about listeners?A. The return value from a listener is of boolean type.B. Most components allow multiple listeners to be added.C. A copy of the original event is passed into a listener method.D. If multiple listeners are added to a single component, they all must all be friends to each other.E. If the multiple listeners are added to a single component, the order [in which listeners are called is guaranteed].BC.5. What might cause the current thread to stop executing.A. An InterruptedException is thrown.B. The thread executes a wait() call.C. The thread constructs a new Thread.D. A thread of higher priority becomes ready.E. The thread executes a waitforID() call on a MediaTracker.ABDE.6. Given the following incomplete method.1. public void method(){2.3. if (someTestFails()){4.5. }6.7.}You want to make this method throw an IOException if, and only if, the method someTestFails() returns a value of true.Which changes achieve this?A. Add at line 2: IOException e;B. Add at line 4: throw e;C. Add at line 4: throw new IOException();D. Add at line 6: throw new IOException();E. Modify the method declaration to indicate that an object of [type] Exception might be thrown.CE.7. Which modifier should be applied to a method for the lock of the object this to beobtained prior to executing any of the method body?A. finalB. staticC. abstractD. protectedE. synchronizedE.8. Which are keywords in Java?A. NULLB. trueC. sizeofD. implementsE. instanceofDE.9. Consider the following code:Integer s = new Integer(9);Integer t = new Integer(9);Long u = new Long(9);Which test would return true?A. (s==u)B. (s==t)C. (s.equals(t))D. (s.equals(9))E. (s.equals(new Integer(9))CE.10. Why would a responsible Java programmer want to use a nested class?A. To keep the code for a very specialized class in close association with the class it works with.B. To support a new user interface that generates custom events.C. To impress the boss with his/her knowledge of Java by using nested classes all over the place.11. You have the following code. Which numbers will cause "Test2" to be printed?switch(x){case 1:System.out.println("Test1");case 2:case 3:System.out.println("Test2");break;}System.out.println("Test3");}A. 0B. 1C. 2D. 3E. 4BCD.12. Which statement declares a variable a which is suitable for referring to an array of 50 string objects?A. char a[][];B. String a[];C. String []a;D. Object a[50];E. String a[50];F. Object a[];BCF.13. What should you use to position a Button within an application frame so that the width of the Button is affected by the Frame size but the height is not affected.A. FlowLayoutB. GridLayoutC. Center area of a BorderLayoutD. East or West of a BorderLayoutE. North or South of a BorderLayout14. What might cause the current thread to stop executing?A. An InterruptedException is thrownB. The thread executes a sleep() callC. The thread constructs a new ThreadD. A thread of higher priority becomes ready (runnable)E. The thread executes a read() call on an InputStreamABDE.Non-runnable states:* Suspended: caused by suspend(), waits for resume()* Sleeping: caused by sleep(), waits for timeout* Blocked: caused by various I/O calls or by failing to get a monitor's lock, waits for I/O or for the monitor's lock* Waiting: caused by wait(), waits for notify() or notifyAll()* Dead: Caused by stop() or returning from run(), no way out15. Consider the following code:String s = null;Which code fragments cause an object of type NullPointerException to be thrown?A. if((s!=null) & (s.length()>0))B. if((s!=null) &&(s.length()>0))C. if((s==null) | (s.length()==0))D. if((s==null) || (s.length()==0))AC.16. Given the following method body:{if (sometest()) {unsafe();}else {safe();}}The method "unsafe" might throw an IOException (which is not a subclass of RunTimeException). Which correctly completes the method of declaration when added at line one?A. public void methodName() throws ExceptionB. public void methodname()C. public void methodName() throw IOExceptionD. public void methodName() throws IOExceptionE. public IOException methodName()AD.17. What would be the result of attempting to compile and run the following piece of code?public class Test {static int x;public static void main(String args[]){System.out.println("Value is " + x);}}A. The output "Value is 0" is printed.B. An object of type NullPointerException is thrown.C. An "illegal array declaration syntax" compiler error occurs.D. A "possible reference before assignment" compiler error occurs.E. An object of type ArrayIndexOutOfBoundsException is thrown.A.18. What would be the result of attempting to compile and run the following piece of code?public class Test {public int x;public static void main(String args[]){System.out.println("Value is " + x);}}A. The output "Value is 0" is printed.B. Non-static variable x cannot be referenced from a static context..C. An "illegal array declaration syntax" compiler error occurs.D. A "possible reference before assignment" compiler error occurs.E. An object of type ArrayIndexOutOfBoundsException is thrown.B.19. What would be the result of attempting to compile and run the following piece of code?public class Test {public static void main(String args[]){int x;System.out.println("Value is " + x);}}A. The output "Value is 0" is printed.B. An object of type NullPointerException is thrown.C. An "illegal array declaration syntax" compiler error occurs.D. A "possible reference before assignment" compiler error occurs.E. An object of type ArrayIndexOutOfBoundsException is thrown.D.。

2020年9月青少年机器人技术等级考试理论综合试卷(三级)含答案

2020年9月青少年机器人技术等级考试理论综合试卷(三级)含答案

2020年9月青少年机器人技术等级考试理论综合试卷(三级)含答案2020年9月分数:100 题数:30一、单选题(共20题,共80分)1.Arduino UNO/Nano主控板,下列程序模块返回值的最大值为?()A. 90B. 180C. 1023D. 2047试题编号:20200828135038059试题类型:单选题标准答案:A试题难度:一般2.我国家庭用电电压和正常状况下人体的安全电压分别为?()A. 220V 24VB. 220V 36VC. 380V 24VD. 380V 36V试题编号:20200828135037591试题类型:单选题标准答案:B试题难度:一般3.下列数据中,不属于模拟信号的有?()A. 声音的音量B. 光线的强弱C. 水龙头流量的变化D. 公园里游园的人数试题编号:20200828135037872试题类型:单选题标准答案:D试题难度:一般试题解析:4.程序如下,串口监视器输出的值是?()A. 4B. 5C. 6D. 不确定试题编号:20200828135038247试题类型:单选题标准答案:B试题难度:一般5.有关串联电路,下列说法不正确的是?()A. 串联电路中各处电流相等B. 串联电路两端的电压等于电路中各部分器件两端电压之和C. 串联电路的总电阻等于电路中各部分器件电阻之和D. 串联电路中开关的作用与其位置有关试题编号:20200828135038278试题类型:单选题标准答案:D试题难度:一般6.Arduino UNO/Nano主控板,执行如下程序模块后,正常情况下,引脚3输出的电压为?()A. 0VB. 1.5VC. 3.5VD. 5V试题编号:20200828135037809试题类型:单选题标准答案:D试题难度:一般7.下图所示的4个电路中,电路搭设正确的是?()A. AB. BC. CD. D试题编号:20200828135037763试题类型:单选题标准答案:D试题难度:一般8.HC-SR04超声波传感器有如下4个引脚,用于将数据传送到主控板的引脚是?()A. GNDB. VCCC. TrigD. Echo试题编号:20200828135038091试题类型:单选题标准答案:D试题难度:一般9.程序模块如下,串口监视器输出的最后一个数值是?()A. 10B. 11C. 12D. 14试题编号:20200828135038169试题类型:单选题标准答案:D试题难度:一般10.Arduino UNO/Nano主控板,具有模拟输出功能的引脚数量是?()A. 6B. 8C. 14D. 20试题编号:20200828135037950试题类型:单选题标准答案:A试题难度:一般11.按键模块连接到2引脚,LED灯模块连接到3引脚,程序如下,下列说法正确的是?()A. 按键按下后LED点亮B. 按键按下后LED灯熄灭C. 按键按下后LED灯闪烁D. 按键按下后,LED灯可能点亮也可能熄灭试题编号:20200828135038122试题类型:单选题标准答案:D试题难度:一般12.Arduino UNO/Nano主控板,图示模拟输入模块返回值的范围是?()A. 0~1B. 0~255C. 255~1023D. 0~1023试题编号:20200828135038013试题类型:单选题标准答案:D试题难度:一般13.以下物质中不是导体的是?()A. 铜线B. 铅笔芯C. 橡皮D. 铁栏杆试题编号:20200828135037638试题类型:单选题标准答案:C试题难度:一般试题解析:14.下列图中LED灯和面包板实现串联的是?()A. AB. BC. CD. D试题编号:20200828135037669试题类型:单选题标准答案:B试题难度:一般15.电路如图所示,通过引脚D6控制LED灯,能让LED灯点亮的程序模块是?()A. AB. BC. CD. D试题编号:20200828135037841试题类型:单选题标准答案:C试题难度:一般16.纯电阻电路中,以下对欧姆定律阐述正确的是?()A. 电路中导体的电流与导体两端的电压成正比,与导体的电阻也成正比B. 电路中导体的电流与导体两端的电压成正比,与导体的电阻也成反比C. 电路中导体的电流与导体两端的电压成反比,与导体的电阻也成正比D. 电路中导体的电流与导体两端的电压成反比,与导体的电阻也成反比试题编号:20200828135037731试题类型:单选题标准答案:B试题难度:一般17.以下模块在流程图绘制时,对应的符号为?()A.B.C.D.试题编号:20200828135037919试题类型:单选题标准答案:D试题难度:一般18.以下表示电源正极的符号有?()A. VccB. -C. GNDD. Vss试题编号:20200828135037700试题类型:单选题标准答案:A试题难度:一般19.如下图所示的循环模块,正常情况下,模块会循环()次。

SCJP官方题库

SCJP官方题库

QUESTION NO: 1Given:1. public class Threads2 implements Runnable {2.3. public void run() {4. System.out.println("run.");5. throw new RuntimeException("Problem");6. }7. public static void main(String[] args) {8. Thread t = new Thread(new Threads2());9. t.start();10. System.out.println("End of method.");11. }12. }Which two can be results? (Choose two.)A. ng.RuntimeException: ProblemB. runng.RuntimeException: ProblemC. End of method.ng.RuntimeException: ProblemD. End of method.run.ng.RuntimeException: ProblemE. runng.RuntimeException: ProblemEnd of method.Answer: D,EQUESTION NO: 2Which two statements are true? (Choose two.)A. It is possible for more than two threads to deadlock at once.B. The JVM implementation guarantees that multiple threads cannot enter into a deadlocked state.C. Deadlocked threads release once their sleep() method's sleep duration has expired.D. Deadlocking can occur only when the wait(), notify(), and notifyAll() methods are usedincorrectly.E. It is possible for a single-threaded application to deadlock if synchronized blocks are usedincorrectly.F. If a piece of code is capable of deadlocking, you cannot eliminate the possibility of deadlockingby inserting invocations of Thread.yield().Answer: A,FQUESTION NO: 3Given:7. void waitForSignal() {8. Object obj = new Object();9. synchronized (Thread.currentThread()) {10. obj.wait();11. obj.notify();12. }13. }Which statement is true?A. This code can throw an InterruptedException.B. This code can throw an IllegalMonitorStateException.C. This code can throw a TimeoutException after ten minutes.D. Reversing the order of obj.wait() and obj.notify() might cause this method to complete normally.E. A call to notify() or notifyAll() from another thread might cause this method to completenormally.F. This code does NOT compile unless "obj.wait()" is replaced with "((Thread)obj).wait()".Answer: BQUESTION NO: 4Click the Exhibit button.What is the output if the main() method is run?A. 4B. 5C. 8D. 9E. Compilation fails.F. An exception is thrown at runtime.G. It is impossible to determine for certain. Answer: DQUESTION NO: 5Given:11. class PingPong2 {12. synchronized void hit(long n) {13. for(int i = 1; i < 3; i++)14. System.out.print(n + "-" + i + " ");15. }16. }17. public class Tester implements Runnable {18. static PingPong2 pp2 = new PingPong2();19. public static void main(String[] args) {20. new Thread(new Tester()).start();21. new Thread(new Tester()).start();22. }23. public void run() { pp2.hit(Thread.currentThread().getId()); }24. }Which statement is true?A. The output could be 5-1 6-1 6-2 5-2B. The output could be 6-1 6-2 5-1 5-2C. The output could be 6-1 5-2 6-2 5-1D. The output could be 6-1 6-2 5-1 7-1 Answer: BQUESTION NO: 6Given:1. public class Threads4 {2. public static void main (String[] args) {3. new Threads4().go();4. }5. public void go() {6. Runnable r = new Runnable() {7. public void run() {8. System.out.print("foo");9. }10. };11. Thread t = new Thread(r);12. t.start();13. t.start();14. }15. }What is the result?A. Compilation fails.B. An exception is thrown at runtime.C. The code executes normally and prints "foo".D. The code executes normally, but nothing is printed. Answer: BQUESTION NO: 7Given:11. public abstract class Shape {12. private int x;13. private int y;14. public abstract void draw();15. public void setAnchor(int x, int y) {16. this.x = x;17. this.y = y;18. }19. }Which two classes use the Shape class correctly? (Choose two.)A. public class Circle implements Shape {private int radius;}B. public abstract class Circle extends Shape { private int radius;}C. public class Circle extends Shape {private int radius;public void draw();}D. public abstract class Circle implements Shape { private int radius;public void draw();}E. public class Circle extends Shape {private int radius;public void draw() {/* code here */}F. public abstract class Circle implements Shape { private int radius;public void draw() { /* code here */ } Answer: B,EQUESTION NO: 8Given:11. public class Barn {12. public static void main(String[] args) {13. new Barn().go("hi", 1);14. new Barn().go("hi", "world", 2);15. }16. public void go(String... y, int x) {17. System.out.print(y[y.length - 1] + " ");18. }19. }What is the result?A. hi hiB. hi worldC. world worldD. Compilation fails.E. An exception is thrown at runtime.Answer: DQUESTION NO: 9Given:10. class Nav{11. public enum Direction { NORTH, SOUTH, EAST, WEST }12. }13. public class Sprite{14. // insert code here15. }Which code, inserted at line 14, allows the Sprite class to compile?A. Direction d = NORTH;B. Nav.Direction d = NORTH;C. Direction d = Direction.NORTH;D. Nav.Direction d = Nav.Direction.NORTH; Answer: DQUESTION NO: 10Click the Exhibit button.Which statement is true about the classes and interfaces in the exhibit?A. Compilation will succeed for all classes and interfaces.B. Compilation of class C will fail because of an error in line 2.C. Compilation of class C will fail because of an error in line 6.D. Compilation of class AImpl will fail because of an error in line 2.Answer: CQUESTION NO: 11Click the Exhibit button.What is the result?A. 4321B. 0000C. An exception is thrown at runtime.D. Compilation fails because of an error in.Answer: DQUESTION NO: 12Given:11. public class Rainbow {12. public enum MyColor {13. RED(0xff0000), GREEN(0x00ff00), BLUE(0x0000ff);14. private final int rgb;15. MyColor(int rgb) { this.rgb = rgb; }16. public int getRGB() { return rgb; }17. }; 18. public static void main(String[] args) {19. // insert code here20. }21. }Which code fragment, inserted at line 19, allows the Rainbow class to compile?A. MyColor skyColor = BLUE;B. MyColor treeColor = MyColor.GREEN;C. if(RED.getRGB() < BLUE.getRGB()) { }D. Compilation fails due to other error(s) in the code.E. MyColor purple = new MyColor(0xff00ff);F. MyColor purple = MyColor.BLUE + MyColor.RED; Answer: BQUESTION NO: 13Given:11. class Mud {12. // insert code here13. System.out.println("hi");14. }15. }And the following five fragments:public static void main(String...a) {public static void main(String.* a) {public static void main(String... a) {public static void main(String[]... a) {public static void main(String...[] a) {How many of the code fragments, inserted independently at line 12, compile?A. 0B. 1C. 2D. 3E. 4F. 5Answer: DQUESTION NO: 14Given:5. class Atom {6. Atom() { System.out.print("atom "); }7. }8. class Rock extends Atom {9. Rock(String type) { System.out.print(type); }10. }11. public class Mountain extends Rock {12. Mountain() {13. super("granite ");14. new Rock("granite ");15. }16. public static void main(String[] a) { new Mountain(); }17. }What is the result?A. Compilation fails.B. atom graniteC. granite graniteD. atom granite graniteE. An exception is thrown at runtime.F. atom granite atom graniteAnswer: FQUESTION NO: 15Given:1. interface TestA { String toString(); }2. public class Test {3. public static void main(String[] args) {4. System.out.println(new TestA() {5. public String toString() { return "test"; }6. });7. }8. }What is the result?A. testB. nullC. An exception is thrown at runtime.D. Compilation fails because of an error in line 1.E. Compilation fails because of an error in line 4.F. Compilation fails because of an error in line 5. Answer: AQUESTION NO: 16Given:11. public static void parse(String str) {12. try {13. float f = Float.parseFloat(str);14. } catch (NumberFormatException nfe) {15. f = 0;16. } finally {17. System.out.println(f);18. }19. }20. public static void main(String[] args) {21. parse("invalid");22. }What is the result?A. 0.0B. Compilation fails.C. A ParseException is thrown by the parse method at runtime.D. A NumberFormatException is thrown by the parse method at runtime.Answer: BQUESTION NO: 17Given:1. public class Blip {2. protected int blipvert(int x) { return 0; }3. }4. class Vert extends Blip {5. // insert code here6. }Which five methods, inserted independently at line 5, will compile? (Choose five.)A. public int blipvert(int x) { return 0; }B. private int blipvert(int x) { return 0; }C. private int blipvert(long x) { return 0; }D. protected long blipvert(int x) { return 0; }E. protected int blipvert(long x) { return 0; }F. protected long blipvert(long x) { return 0; }G. protected long blipvert(int x, int y) { return 0; } Answer: A,C,E,F,GQUESTION NO: 18Given:1. class Super {2. private int a;3. protected Super(int a) { this.a = a; }4. }...11. class Sub extends Super {12. public Sub(int a) { super(a); }13. public Sub() { this.a = 5; }14. }Which two, independently, will allow Sub to compile? (Choose two.)A. Change line 2 to:public int a;B. Change line 2 to:protected int a;C. Change line 13 to:public Sub() { this(5); }D. Change line 13 to:public Sub() { super(5); }E. Change line 13 to:public Sub() { super(a); }Answer: C,DQUESTION NO: 19Which Man class properly represents the relationship "Man has a best friend who is a Dog"?A. class Man extends Dog { }B. class Man implements Dog { }C. class Man { private BestFriend dog; }D. class Man { private Dog bestFriend; }E. class Man { private Dog<bestFriend>; }F. class Man { private BestFriend<dog>; } Answer: DQUESTION NO: 20Given:1. package test;2.3. class Target {4. public String name = "hello";5. }What can directly access and change the value of the variable name?A. any classB. only the Target classC. any class in the test packageD. any class that extends TargetAnswer: CQUESTION NO: 21Given:11. abstract class Vehicle { public int speed() { return 0; }12. class Car extends Vehicle { public int speed() { return 60; }13. class RaceCar extends Car { public int speed() { return 150; }...21. RaceCar racer = new RaceCar();22. Car car = new RaceCar();23. Vehicle vehicle = new RaceCar();24. System.out.println(racer.speed() + ", " + car.speed()25. + ", " + vehicle.speed());What is the result?A. 0, 0, 0B. 150, 60, 0C. Compilation fails.D. 150, 150, 150E. An exception is thrown at runtime.Answer: DQUESTION NO: 22Given:5. class Building { }6. public class Barn extends Building {7. public static void main(String[] args) {8. Building build1 = new Building();9. Barn barn1 = new Barn();10. Barn barn2 = (Barn) build1;11. Object obj1 = (Object) build1;12. String str1 = (String) build1;13. Building build2 = (Building) barn1;14. }15. }Which is true?A. If line 10 is removed, the compilation succeeds.B. If line 11 is removed, the compilation succeeds.C. If line 12 is removed, the compilation succeeds.D. If line 13 is removed, the compilation succeeds.E. More than one line must be removed for compilation to succeed.Answer: CQUESTION NO: 23A team of programmers is reviewing a proposed API for a new utility class. After some discussion,they realize that they can reduce the number of methods in the API without losing anyfunctionality. If they implement the new design, which two OO principles will they be promoting?A. Looser couplingB. Tighter couplingC. Lower cohesionD. Higher cohesionE. Weaker encapsulationF. Stronger encapsulationAnswer: AQUESTION NO: 24 Given:21. class Money {22. private String country = "Canada";23. public String getC() { return country; }24. }25. class Yen extends Money {26. public String getC() { return super.country; }27. }28. public class Euro extends Money {29. public String getC(int x) { return super.getC(); }30. public static void main(String[] args) {31. System.out.print(new Yen().getC() + " " + newEuro().getC());32. }33. }What is the result?A. CanadaB. nullCanadaC. Canada nullD. Canada CanadaE. Compilation fails due to an error on line 26.F. Compilation fails due to an error on line 29. Answer: EQUESTION NO: 25Assuming that the serializeBanana() and the deserializeBanana() methods will correctly use Java serialization and given:13. import java.io.*;14. class Food implements Serializable {int good = 3;}15. class Fruit extends Food {int juice = 5;}16. public class Banana extends Fruit {17. int yellow = 4;18. public static void main(String [] args) {19. Banana b = new Banana(); Banana b2 = new Banana();20. b.serializeBanana(b); // assume correct serialization21. b2 = b.deserializeBanana(); // assume correct22. System.out.println("restore "+b2.yellow+b2.juice+b2.good);24. }25. // more Banana methods go here50. }What is the result?A. restore 400B. restore 403C. restore 453D. Compilation fails.E. An exception is thrown at runtime.Answer: CQUESTION NO: 26Given a valid DateFormat object named df, and16. Date d = new Date(0L);17. String ds = "December 15, 2004";18. // insert code hereWhat updates d's value with the date represented by ds?A. 18. d = df.parse(ds);B. 18. d = df.getDate(ds);C. 18. try {19. d = df.parse(ds);20. } catch(ParseException e) { };D. 18. try {19. d = df.getDate(ds);20. } catch(ParseException e) { };Answer: CQUESTION NO: 27Given:11. double input = 314159.26;12. NumberFormat nf =NumberFormat.getInstance(Locale.ITALIAN);13. String b;14. //insert code hereWhich code, inserted at line 14, sets the value of b to 314.159,26?A. b = nf.parse( input );B. b = nf.format( input );C. b = nf.equals( input );D. b = nf.parseObject( input );Answer: BQUESTION NO: 28Given:1. public class TestString1 {2. public static void main(String[] args) {3. String str = "420";4. str += 42;5. System.out.print(str);6. }7. }What is the output?A. 42B. 420C. 462D. 42042E. Compilation fails.F. An exception is thrown at runtime.Answer: DQUESTION NO: 29Which capability exists only in java.io.FileWriter?A. Closing an open stream.B. Flushing an open stream.C. Writing to an open stream.D. Writing a line separator to an open stream. Answer: DQUESTION NO: 30Given that the current directory is empty, and that the user has read and write permissions, andthe following:11. import java.io.*;12. public class DOS {13. public static void main(String[] args) {14. File dir = new File("dir");15. dir.mkdir(); 16. File f1 = new File(dir, "f1.txt");17. try {18. f1.createNewFile();19. } catch (IOException e) { ; }20. File newDir = new File("newDir");21. dir.renameTo(newDir);22. }23. }Which statement is true?A. Compilation fails.B. The file system has a new empty directory named dir.C. The file system has a new empty directory named newDir.D. The file system has a directory named dir, containing a file f1.txt.E. The file system has a directory named newDir, containing a file f1.txt.Answer: EQUESTION NO: 31Given:22. StringBuilder sb1 = new StringBuilder("123");23. String s1 = "123";24. // insert code here25. System.out.println(sb1 + " " + s1);Which code fragment, inserted at line 24, outputs "123abc 123abc"?A. sb1.append("abc"); s1.append("abc");B. sb1.append("abc"); s1.concat("abc");C. sb1.concat("abc"); s1.append("abc");D. sb1.concat("abc"); s1.concat("abc");E. sb1.append("abc"); s1 = s1.concat("abc");F. sb1.concat("abc"); s1 = s1.concat("abc");G. sb1.append("abc"); s1 = s1 + s1.concat("abc");H. sb1.concat("abc"); s1 = s1 + s1.concat("abc"); Answer: EQUESTION NO: 32Click the Exhibit button.Which code, inserted at line 14, will allow this class tocorrectly serialize and deserialize?A. s.defaultReadObject();B. this = s.defaultReadObject();C. y = s.readInt(); x = s.readInt();D. x = s.readInt(); y = s.readInt();Answer: DQUESTION NO: 33Given:1. public class LineUp {2. public static void main(String[] args) {3. double d = 12.345;4. // insert code here5. }6. }Which code fragment, inserted at line 4, produces the output | 12.345|?A. System.out.printf("|%7d| \n", d);B. System.out.printf("|%7f| \n", d);C. System.out.printf("|%3.7d| \n", d);D. System.out.printf("|%3.7f| \n", d);E. System.out.printf("|%7.3d| \n", d);F. System.out.printf("|%7.3f| \n", d);Answer: FQUESTION NO: 34Given:11. public class Test {12. public static void main(String [] args) {13. int x = 5;14. boolean b1 = true;15. boolean b2 = false;16.17. if ((x == 4) && !b2 )18. System.out.print("1 ");19. System.out.print("2 ");20. if ((b2 = true) && b1 )21. System.out.print("3 ");22. }23. }What is the result?A. 2B. 3C. 1 2D. 2 3E. 1 2 3F. Compilation fails.G. An exception is thrown at runtime. Answer: DQUESTION NO: 35Given:10. interface Foo {}11. class Alpha implements Foo {}12. class Beta extends Alpha {}13. class Delta extends Beta {14. public static void main( String[] args ) {15. Beta x = new Beta(); 16. // insert code here17. }18. }Which code, inserted at line 16, will cause ang.ClassCastException?A. Alpha a = x;B. Foo f = (Delta)x;C. Foo f = (Alpha)x;D. Beta b = (Beta)(Alpha)x;Answer: BQUESTION NO: 36Given:22. public void go() {23. String o = "";24. z:25. for(int x = 0; x < 3; x++) {26. for(int y = 0; y < 2; y++) {27. if(x==1) break;28. if(x==2 && y==1) break z;29. o = o + x + y;30. }31. }32. System.out.println(o);33. }What is the result when the go() method is invoked?A. 00B. 0001C. 000120D. 00012021E. Compilation fails.F. An exception is thrown at runtime.Answer: CQUESTION NO: 37Given:11. static void test() throws RuntimeException {12. try {13. System.out.print("test ");14. throw new RuntimeException();15. }16. catch (Exception ex) { System.out.print("exception "); }17. }18. public static void main(String[] args) {19. try { test(); }20. catch (RuntimeException ex){ System.out.print("runtime "); }21. System.out.print("end ");22. }What is the result?A. test endB. Compilation fails.C. test runtime endD. test exception endE. A Throwable is thrown by main at runtime. Answer: DQUESTION NO: 38Given:33. try {34. // some code here35. } catch (NullPointerException e1) {36. System.out.print("a");37. } catch (Exception e2) {38. System.out.print("b");39. } finally {40. System.out.print("c");41. }If some sort of exception is thrown at line 34, which output is possible?A. aB. bC. cD. acE. abcAnswer: DQUESTION NO: 39Given:31. // some code here32. try {33. // some code here34. } catch (SomeException se) {35. // some code here36. } finally {37. // some code here38. }Under which three circumstances will the code on line 37 be executed? (Choose three.)A. The instance gets garbage collected.B. The code on line 33 throws an exception.C. The code on line 35 throws an exception.D. The code on line 31 throws an exception.E. The code on line 33 executes successfully. Answer: B,C,EQUESTION NO: 40Given:10. int x = 0;11. int y = 10;12. do {13. y--;14. ++x;15. } while (x < 5);16. System.out.print(x + "," + y);What is the result?A. 5,6B. 5,5C. 6,5D. 6,6Answer: BQUESTION NO: 41Given:1. public class Donkey2 {2. public static void main(String[] args) {3. boolean assertsOn = true;4. assert (assertsOn) : assertsOn = true;5. if(assertsOn) {6. System.out.println("assert is on");7. }8. }9. }If class Donkey is invoked twice, the first time without assertions enabled, and the second timewith assertions enabled, what are the results?A. no outputB. no output assert is onC. assert is onD. no outputAn AssertionError is thrown.E. assert is onAn AssertionError is thrown.Answer: CQUESTION NO: 42Click the Exhibit button.Given:31. public void method() {32. A a = new A();33. a.method1();34. }Which statement is true if a TestException is thrown on line 3 of class B?A. Line 33 must be called within a try block.B. The exception thrown by method1 in class A is not required to be caught.C. The method declared on line 31 must be declared to throw a RuntimeException.D. On line 5 of class A, the call to method2 of class B does not need to be placed in atry/catch block.Answer: BQUESTION NO: 43Given:11. Float pi = new Float(3.14f);12. if (pi > 3) {13. System.out.print("pi is bigger than 3. ");14. }15. else {16. System.out.print("pi is not bigger than 3. ");17. }18. finally {19. System.out.println("Have a nice day.");20. }What is the result?A. Compilation fails.B. pi is bigger than 3.C. An exception occurs at runtime.D. pi is bigger than 3. Have a nice day.E. pi is not bigger than 3. Have a nice day. Answer: AQUESTION NO: 44Given:1. public class Boxer1{2. Integer i;3. int x;4. public Boxer1(int y) {5. x = i+y;6. System.out.println(x);7. }8. public static void main(String[] args) {9. new Boxer1(new Integer(4));10. }11. }What is the result?A. The value "4" is printed at the command line.B. Compilation fails because of an error in line 5.C. Compilation fails because of an error in line 9.D. A NullPointerException occurs at runtime.E. A NumberFormatException occurs at runtime.F. An IllegalStateException occurs at runtime. Answer: DQUESTION NO: 45Given:1. public class Person {2. private String name;3. public Person(String name) { = name; }4. public boolean equals(Person p) {5. return .equals();6. }7. }Which statement is true?A. The equals method does NOT properly override the Object.equals method.B. Compilation fails because the private attribute cannot be accessed in line 5.C. To work correctly with hash-based data structures, this class must also implement thehashCode method.D. When adding Person objects to a java.util.Set collection, the equals method in line 4 willprevent duplicates. Answer: AQUESTION NO: 46Which two statements are true about the hashCode method? (Choose two.)A. The hashCode method for a given class can be used to test for object equality and objectinequality for that class.B. The hashCode method is used by thejava.util.SortedSet collection class to order the elements within that set.C. The hashCode method for a given class can be used to test for object inequality, butNOT object equality, for that class.D. The only important characteristic of the values returned by a hashCode method is that thedistribution of values must follow a Gaussian distribution.E. The hashCode method is used by the java.util.HashSet collection class to group the elementswithin that set into hash buckets for swift retrieval.Answer: C,EQUESTION NO: 47Given:1. public class Score implements Comparable<Score> {2. private int wins, losses;3. public Score(int w, int l) { wins = w; losses = l; }4. public int getWins() { return wins; }5. public int getLosses() { return losses; }6. public String toString() {7. return "<" + wins + "," + losses + ">";8. }9. // insert code here10. }Which method will complete this class?A. public int compareTo(Object o){/*more code here*/}B. public int compareTo(Score other){/*more code here*/}C. public int compare(Score s1,Score s2){/*more code here*/}D. public int compare(Object o1,Object o2){/*more code here*/}Answer: BQUESTION NO: 48Given a pre-generics implementation of a method:11. public static int sum(List list) {12. int sum = 0;13. for ( Iterator iter = list.iterator(); iter.hasNext(); ) {14. int i = ((Integer)iter.next()).intValue();15. sum += i;16. }17. return sum;18. }What three changes allow the class to be used with generics and avoid an unchecked warning?(Choose three.)A. Remove line 14.B. Replace line 14 with "int i = iter.next();".C. Replace line 13 with "for (int i : intList) {".D. Replace line 13 with "for (Iterator iter : intList) {".E. Replace the method declaration with "sum(List<int> intList)".F. Replace the method declaration with"sum(List<Integer> intList)".Answer: A,C,FQUESTION NO: 49Given:23. Object [] myObjects = {24. new Integer(12),25. new String("foo"),26. new Integer(5),27. new Boolean(true)28. };29. Arrays.sort(myObjects);30. for(int i=0; i<myObjects.length; i++) {31. System.out.print(myObjects[i].toString());32. System.out.print(" ");33. }What is the result?A. Compilation fails due to an error in line 23.B. Compilation fails due to an error in line 29.C. A ClassCastException occurs in line 29.D. A ClassCastException occurs in line 31.E. The value of all four objects prints in natural order. Answer: CQUESTION NO: 50Given a class Repetition:1. package utils;2.3. public class Repetition {4. public static String twice(String s) { return s + s; }5. }and given another class Demo:1. // insert code here2.3. public class Demo {4. public static void main(String[] args) {5. System.out.println(twice("pizza"));6. }7. }Which code should be inserted at line 1 of Demo.java to compile and run Demo to print"pizzapizza"?A. import utils.*;B. static import utils.*;C. import utils.Repetition.*;D. static import utils.Repetition.*;E. import utils.Repetition.twice();F. import static utils.Repetition.twice;G. static import utils.Repetition.twice;Answer: FQUESTION NO: 51A UNIX user named Bob wants to replace his chess program with a new one, but he is not surewhere the old one is installed. Bob is currently able to run a Java chess program starting from hishome directory /home/bob using the command:java -classpath /test:/home/bob/downloads/*.jar games.ChessBob's CLASSPATH is set (at login time) to:/usr/lib:/home/bob/classes:/opt/java/lib:/opt/java/lib/*.jar What is a possible location for the Chess.class file?A. /test/Chess.classB. /home/bob/Chess.classC. /test/games/Chess.classD. /usr/lib/games/Chess.classE. /home/bob/games/Chess.classF. inside jarfile /opt/java/lib/Games.jar (with a correct manifest)G. inside jarfile /home/bob/downloads/Games.jar (with a correct manifest)Answer: CQUESTION NO: 52Given the following directory structure:bigProject|--source| |--Utils.java||--classes|--And the following command line invocation:javac -d classes source/Utils.javaAssume the current directory is bigProject, what is the result?A. If the compile is successful, Utils.class is added to the source directory.B. The compiler returns an invalid flag error.C. If the compile is successful, Utils.class is added to the classes directory.D. If the compile is successful, Utils.class is added to the bigProject directory.Answer: CQUESTION NO: 53Given:1. package pany.application;2.3. public class MainClass {4. public static void main(String[] args) {}5. }And MainClass exists in the/apps/com/company/application directory. Assume the CLASSPATH environment variable is set to "." (current directory).Which two java commandsentered at the command line will run MainClass? (Choose two.)A. java MainClass if run from the /apps directoryB. java pany.application.MainClass if run from the /apps directoryC. java -classpath /appspany.application.MainClass if run from any directoryD. java -classpath . MainClass if run from the/apps/com/company/application directory。

全国青少年机器人技术等级考试理论综合试卷三级测试卷

全国青少年机器人技术等级考试理论综合试卷三级测试卷

全国青少年机器人技术等级考试理论综合试卷(三级)测试卷一、单选题(共30题,每题2分,共60分)正常情况下,程序中,当引脚4输入的电压为2.5V时,串试题编号:20181130161925008试题类型:单选题标准答案:D试题难度:一般试题解析:考生答案:考生得分:0是否评分:已评分评价描述:试题编号:20181130161924785试题类型:单选题标准答案:A试题难度:一般试题解析:考生答案:考生得分:0是否评分:已评分评价描述:运行下图程序,串口监视器窗口输出数值为?试题编号:20181130161925045试题类型:单选题标准答案:C试题难度:一般试题解析:考生答案:考生得分:0是否评分:已评分评价描述:D. 没有规律试题编号:20181130161924801试题类型:单选题标准答案:B试题难度:一般试题解析:考生答案:考生得分:0是否评分:已评分评价描述:A. 1.5VB. 3VC. 6VD. 36V试题编号:20181130161924867试题类型:单选题标准答案:A试题难度:一般试题解析:考生答案:考生得分:0是否评分:已评分评价描述:Arduino UNO或Nano主控板,通过电位器旋转控制LED的亮度,程序运行下列表达正确的是?C. 电位器从一端旋转至另外一端时,LED灯的状态从最亮渐变到熄灭四次。

D. 电位器从一端旋转至另外一端时,LED灯的状态只有亮灭两种状态。

试题编号:20181130161925024试题类型:单选题标准答案:C试题难度:一般试题解析:考生答案:考生得分:0是否评分:已评分评价描述:A.B.C.试题编号:20181130161924977试题类型:单选题标准答案:C试题难度:一般试题解析:考生答案:考生得分:0是否评分:已评分评价描述:8. 下列电路图中LED1和LED2为5mm红色LED灯,下列表达正确的是?A. LED1 和LED1 均点亮B. 仅LED1点亮C. 仅LED2点亮D. LED1和LED2均不亮试题编号:20181130161924821 试题类型:单选题标准答案:C试题难度:一般试题解析:考生答案:考生得分:0是否评分:已评分评价描述:A.B.D.试题编号:20181130161924898试题类型:单选题标准答案:A试题难度:一般试题解析:考生答案:考生得分:0是否评分:已评分评价描述:如图所示电路,分析灯L1、灯L2及电压表的连接方式,下列选项正确的是?A. L1、L2、电压表都是并联B. L1、L2、电压表都是串联C. L1与L2串联,L1与电压表并联D. L1与L2并联,L1与电压表串联试题编号:20181130161924851试题类型:单选题标准答案:C试题难度:一般试题解析:考生答案:考生得分:0是否评分:已评分评价描述:11.关于超声波模块说法正确的是?A. 超声波传感器返回的是模拟信号;B. Trig引脚是接受引脚;C. Echo引脚是触发引脚;D. 超声波传感器返回的超声波从发射到返回所经历的时间。

SUN公司SCJP题库讲解学习

SUN公司SCJP题库讲解学习

S U N公司S C J P题库yModule 1-JAVA 基础一、选择题:Question 1Given:35. String #name = "Jane Doe";36. int $age=24;37. Double _height = 123.5;38. double ~temp = 37.5;Which two are true? (Choose two.)A. Line 35 will not compile.B. Line 36 will not compile.C. Line 37 will not compile.D. Line 38 will not compile.Answer: AD 标识符以字母,下划线,或者$开始Question 2Given:11. public class Test {12. public static void main(String [] args) {13. int x =5;14. boolean b1 = true;15. boolean b2 = false;16.17.if((x==4) && !b2)18. System.out.print("l ");19. System.out.print("2 ");20. if ((b2 = true) && b1)21. System.out.print("3");22. }23. }What is the result?A. 2B. 3C. 1 2D. 2 3E. 1 2 3F. Compilation fails.G. An exceptional is thrown at runtime. Answer: D 注意20行,=为赋值,不要被骗Question 3Given:42. public class ClassA {43. public int getValue() {44. int value=0;45. boolean setting = true;46. String title="Hello";47. if (value || (setting && title == "Hello")) { return 1; }48. if (value == 1 & title.equals("Hello")) { return 2; }49. }50. }And:70. ClassA a = new ClassA();71. a.getValue();What is the result?A. 1B. 2C. Compilation fails.D. The code runs with no output.E. An exception is thrown at runtime.Answer: C 编译不通过,47行value为int类型不是boolean Question 4Given:11. public void testIfA() {12. if(testIfB("True")) {13. System.out.println("True");14. } else {15. System.out.println("Not true");16. }17. }18. public Boolean testIfB(String str) {19. return Boolean.valueOf(str);20. }What is the result when method testIfA is invoked?A. TrueB. Not trueC. An exception is thrown at runtime.D. Compilation fails because of an error at line 12.E. Compilation fails because of an error at line 19. Answer: A 19行,如果str为true则返回ture,否则返回false Question 5Given:11. public static void main(String[] args) {12. Integer i = new Integer(1) + new Integer(2);13. switch(i) {14. case 3: System.out.println("three"); break;15. default: System.out.println("other"); break;16. }17. }What is the result?A. threeB. otherC. An exception is thrown at runtime.D. Compilation fails because of an error on line 12.E. Compilation fails because of an error on line 13.F. Compilation fails because of an error on line 15. Answer: A 就是两个Integer类型相加Question 6Given:11. public static void main(String[] args) {12. String str = "null";13. if (str == null) {14. System.out.println("null");15. } else (str.length() == 0) {16. System.out.println("zero");17. } else {18. System.out.println("some");19. }20. }‘What is the result?A. nullB. zeroC. someD. Compilation fails.E. An exception is thrown at runtime.Answer: D 这题真恶心 15行少个ifQuestion 7Given:10.int x=0;11.int y=10;12. do {l3. y--;14. ++x;15. } while (x < 5);16. System.out.print(x + "," + y);What is the result?A. 5,6B. 5,5C. 6,5D. 6,6Answer: B (91,82,73,64,55)没啥争议Question 8Given:25.int x=12;26. while (x < 10) {27. x--;28. }29. System.out.print(x);What is the result?A. 0B. 10C. 12D. Line 29 will never be reached.Answer: C 12>10,所以直接跳出循环,输出x=12 Question 9Given:35. int x= 10;36. do {37. x--;38. } while(x< 10);How many times will line 37 be executed?A. ten timesB. zero timesC. one to me timesD. more than ten timesAnswer: D 死循环Question 10Given:11. public static void main(String[] args) {12. for (int i=0;i<= 10;i++){13. if( i>6) break;14. }15. System.out.println(i);16. }What is the result?A. 6B. 7C. 10D. 11E. Compilation fails.F. An exception is thrown at runtime. Answer: E 15行i超出了作用域Question 11Given:55. int []x= {1, 2,3,4, 5};56. int y[] =x;57. System.out.println(y[2]);Which is true?A. Line 57 will print the value 2.B. Line 57 will print the value 3.C. Compilation will fail because of an error in line 55.D. Compilation will fail because of an error in line 56. Answer: B 没争议,考察数组下标是从0开始Question 12Which two code fragments(片段) correctly(正确) create and initialize a static array of int elements? (Choose two.)A. static final int[] a = { 100,200 };B. static final int[] a;static { a=new int[2]; a[0]=100; a[1]=200; }C. static final int[] a = new int[2] { 100,200 };D. static final int[] a;static void init() { a = new int[3]; a[0]=100; a[1]=200; } Answer: AB c不能指定长度,d不能在init方法中赋值,要么在static 代码块中Question 13Given:11. public static void main(String[] args) {12. Object obj = new int[] { 1,2,3 };13. int[] someArray = (int[])obj;14. for (int i: someArray) System.out.print(i +" ")15. }‘What is the result?A. 1 2 3B. Compilation fails because of an error in line 12.C. Compilation fails because of an error in line 13.D. Compilation fails because of an error in line 14.E. A ClassCastException is thrown at runtime.Answer: A 没争议,foeach循环遍历数组Question 14Given:11. String[] elements = { "for", "tea", "too" };12. String first = (elements.length > 0)? elements[0] : null;What is the result?A. Compilation fails.B. An exception is thrown at runtime.C. The variable first is set to null.D. The variable first is set to elements[0].Answer: DQuestion 15Given:10. public class Bar {11.static void foo(int...x) {12. // insert code here13. }14. }Which two code fragments, inserted independently(独立的) at line 12, will allow the class to compile? (Choose two.)A. foreach(x) System.out.println(z);B. for(int z : x) System.out.println(z);C. while( x.hasNext()) System.out.println( x.next());D. for( int i=0; i< x.length; i++ )System.out.println(x[i]);Answer: BD x相当于一个数组,a明显错没有foreach,c中x没有hadNext方法Question 16A programmer(程序员) needs to create a logging method that can accept(接受) an arbitrary(随意任意) number of arguments. For example, it may be called in theseways:logIt("log message 1 ");logIt("log message2”,”log message3");logIt("log message4", "log message5", "log message6");Which declaration(说明) satisfies(符合) this requirement(需求)?A. public void logIt(String * msgs)B. public void logIt(String [] msgs)C. public void logIt(String... msgs)D. public void logIt(String msg1, String msg2, String msg3) Answer: C 可变长参数Question 171. public class A {2. public String doit(int x, int y) {3. return "a";4. }5.6. public String doit(int... vals) {7. return "b";8. }9. }Given:25. A a=new A();26. System.out.println(a.doit(4, 5));What is the result?A. Line 26 prints "a" to System.out.B. Line 26 prints "b" to System.out.C. An exception is thrown at line 26 at runtime.D. Compilation of class A will fail due to an error in line6.Answer: A 确定参数和可变长参数同时存在的时候,优先考虑确定参数的Question 18Given a file GrizzlyBear.java:1. package animals.mammals;2.3. public class GrizzlyBear extends Bear {4. void hunt() {5. Salmon s = findSalmon();6. s.consume();7. }8. }and another file, Salmon.java:1. package animals.fish;2.3. public class Salmon extends Fish {4. void consume() { /* do stuff */ }5. }Assume(假定) both classes are defined in the correct directories for theft packages, and that the Mammal class correctly defines the findSalmon() method. Which two changes allow this code to compile correctly? (Choose two.)A. add public to the start of line 4 in Salmon.javaB. add public to the start of line 4 in GrizzlyBear.javaC. add import animals.mammals.*; at line 2 in Salmon.javaD. add import animals.fish.*; at line 2 in GrizzlyBear.javaE. add import animals.fish.Salmon.*; at line 2 in GrizzlyBear.javaF. add import animals.mammals.GrizzlyBear.*;at line 2 in Salmon.javaAnswer: AD 调用不同包下的类,要先导入,方法权限要设置成public Question 19Given:10. package com.sun.scjp;11. public class Geodetics {12. public static final double DIAMETER = 12756.32; // kilometers13. }Which two correctly access(访问) the DIAMETER member of the Geodetics class? (Choose two.)A. import com.sun.scjp.Geodetics;public class TerraCarta {public double halfway(){ return Geodetics.DIAMETER/2.0; } }B. import static com.sun.scjp.Geodetics;public class TerraCarta {public double halfway() { return DIAMETER/2.0; } }C. import static com.sun.scjp.Geodetics. *;public class TerraCarta {public double halfway() { return DIAMETER/2.0; } }D. package com.sun.scjp;public class TerraCarta {public double halfway() { return DIAMETER/2.0; } }Answer: AC b中不能静态导入类,c中静态导入类属性,正确,d访问错误很明显Question 20Given classes defined in two different files:1. package util;2. public class BitUtils {3. private static void process(byte[] b) { }4. }1. package app;2. public class SomeApp {3. public static void main(String[] args) {4. byte[] bytes = new byte[256];5. // insert code here6. }7. }What is required(必需的) at line 5 in class SomeApp to use the process methodof BitUtils?A. process(bytes);B. BitUtils.process(bytes);C. app.BitUtils.process(bytes);D. util.BitUtils.process(bytes);E. import util.BitUtils. *; process(bytes);F. SomeApp cannot use the process method in BitUtils. Answer: F 私有的,不能被访问Question 21Given a class Repetition(重复):1. package utils;2.3. public class Repetition {4. public static String twice(String s) { return s + s; }5. }and given another class Demo:1. // insert code here2.3. public class Demo {4. public static void main(String[] args) {5. System.out.println(twice("pizza"));6. }7. }Which code should be inserted at line 1 of Demo.java to compile and run Demo to print “pizzapizza”?A. import utils.*;B. static import utils.*;C. import utils.Repetition.*;D. static import utils.Repetition. *;E. import utils.Repetition.twice();F. import static utils.Repetition.twice;G. static import utils.Repetition.twice;Answer: F 静态导入Question 22Given:1. package test;2.3. class Target(目标) {4. public String name = "hello";5. }What can directly(直接的) access and change the value ofthe variable(变量) name?A. any classB. only the Target classC. any class in the test packageD. any class that extends TargetAnswer: C default类型的类本包访问权限Question 23Given:11. rbo = new ReallyBigObject();12. // more code here13. rbo = null;14. /* insert code here */Which statement(语句) should be placed at line 14 tosuggest(促成) that the virtual machine(虚拟机) expend(消耗) effort(努力) toward recycling(回收) the memory used by the object rbo?A. System.gc();B. Runtime.gc();C. System.freeMemory();D. Runtime.getRuntime().growHeap();E. Runtime.getRuntime().freeMemory();Answer: A 题很简单。

(整理)SCJP认证试题及答案.

(整理)SCJP认证试题及答案.

转载对题目和答案谨做参考Q1A method is ...1) an implementation of an abstraction.2) an attribute defining the property of a particular abstraction.3) a category of objects.4) an operation defining the behavior for a particular abstraction.5) a blueprint for making operations.Q2An object is ...1) what classes are instantiated from.2) an instance of a class.3) a blueprint for creating concrete realization of abstractions.4) a reference to an attribute.5) a variable.Q3Which line contains a constructor in this class definition?public class Counter { // (1)int current, step;public Counter(int startValue, int stepValue) { // (2)set(startValue);setStepValue(stepValue);}public int get() { return current; } // (3)public void set(int value) { current = value; } // (4)public void setStepValue(int stepValue) { step = stepValue; } // (5) }1) Code marked with (1) is a constructor2) Code marked with (2) is a constructor3) Code marked with (3) is a constructor4) Code marked with (4) is a constructor5) Code marked with (5) is a ConstructorQ4Given that Thing is a class, how many objects and reference variables are created by the following code?Thing item, stuff;item = new Thing();Thing entity = new Thing();1) One object is created2) Two objects are created3) Three objects are created4) One reference variable is created5) Two reference variables are created6) Three reference variables are created.Q5An instance member…1) is also called a static member2) is always a variable3) is never a method4) belongs to a single instance, not to the class as a whole5) always represents an operationQ6How do objects pass messages in Java?1) They pass messages by modifying each other's member variables2) They pass messages by modifying the static member variables of each other's classes3) They pass messages by calling each other's instance member methods4) They pass messages by calling static member methods of each other's classes.Q7Given the following code, which statements are true?class A {int value1;}class B extends A {int value2;}1) Class A extends class B.2) Class B is the superclass of class A.3) Class A inherits from class B.4) Class B is a subclass of class A.5) Objects of class A have a member variable named value2.Q8If this source code is contained in a file called SmallProg.java, what command should be used to compile it using the JDK?public class SmallProg {public static void main(String args[]) { System.out.println("Good luck!"); }}1) java SmallProg2) avac SmallProg3) java SmallProg.java4) javac SmallProg.java5) java SmallProg mainQ9Given the following class, which statements can be inserted at position 1 without causing the code to fail compilation?public class Q6db8 {int a;int b = 0;static int c;public void m() {int d;int e = 0;// Position 1}}1) a++;2) b++;3) c++;4) d++;5) e++;Q10Which statements are true concerning the effect of the >> and >>> operators?1) For non-negative values of the left operand, the >> and >>> operators will have the same effect.2) The result of (-1 >> 1) is 0.3) The result of (-1 >>> 1) is -1.4) The value returned by >>> will never be negative as long as the value of the right operand is equal to or greater than 1.5) When using the >> operator, the leftmost bit of the bit representation of the resulting value will always be the same bit value as the leftmost bit of the bit representation of the left operand.Q11What is wrong with the following code?class MyException extends Exception {}public class Qb4ab {public void foo() {try {bar();} finally {baz();} catch (MyException e) {}}public void bar() throws MyException {throw new MyException();}public void baz() throws RuntimeException {throw new RuntimeException();}}1) Since the method foo() does not catch the exception generated by the method baz(), it must declare the RuntimeException in its throws clause.2) A try block cannot be followed by both a catch and a finally block.3) An empty catch block is not allowed.4) A catch block cannot follow a finally block.5) A finally block must always follow one or more catch blocks.Q12What will be written to the standard output when the following program is run?public class Qd803 {public static void main(String args[]) {String word = "restructure";System.out.println(word.substring(2, 3));}}1) est2) es3) str4) st5) sQ13Given that a static method doIt() in a class Work represents work to be done, what block of code willsucceed in starting a new thread that will do the work?CODE BLOCK A:Runnable r = new Runnable() {public void run() {Work.doIt();}};Thread t = new Thread(r);t.start();CODE BLOCK B:Thread t = new Thread() {public void start() {Work.doIt();}};t.start();CODE BLOCK C:Runnable r = new Runnable() {public void run() {Work.doIt();}};r.start();CODE BLOCK D:Thread t = new Thread(new Work());t.start();CODE BLOCK E:Runnable t = new Runnable() {public void run() {Work.doIt();}};t.run();1) Code block A.2) Code block B.3) Code block C.4) Code block D.5) Code block E.Q14Write a line of code that declares a variable named layout of type LayoutManager and initializes it with a new object, which when used with a container can lay out components in a rectangular grid of equal-sized rectangles, 3 components wide and 2 components high.Q15public class Q275d {static int a;int b;public Q275d() {int c;c = a;a++;b += c;}public static void main(String args[]) {new Q275d();}}1) The code will fail to compile, since the constructor is trying to access static members.2) The code will fail to compile, since the constructor is trying to use static member variable a before it has been initialized.3) The code will fail to compile, since the constructor is trying to use member variable b before it has been initialized.4) The code will fail to compile, since the constructor is trying to use local variable c before it has been initialized.5) The code will compile and run without any problems.Q16What will be written to the standard output when the following program is run?public class Q63e3 {public static void main(String args[]) {System.out.println(9 ^ 2);}}1) 812) 73) 114) 05) falseQ17Which statements are true concerning the default layout manager for containers in the java.awt package?1) Objects instantiated from Panel do not have a default layout manager.2) Objects instantiated from Panel have FlowLayout as default layout manager.3) Objects instantiated from Applet have BorderLayout as default layout manager.4) Objects instantiated from Dialog have BorderLayout as default layout manager.5) Objects instantiated from Window have the same default layout manager as instances of Applet.Q18Which declarations will allow a class to be started as a standalone program?1) public void main(String args[])2) public void static main(String args[])3) public static main(String[] argv)4) final public static void main(String [] array)5) public static void main(String args[])Q19Under which circumstances will a thread stop?1) The method waitforId() in class MediaTracker is called.2) The run() method that the thread is executing ends.3) The call to the start() method of the Thread object returns.4) The suspend() method is called on the Thread object.5) The wait() method is called on the Thread object.Q20When creating a class that associates a set of keys with a set of values, which of these interfaces is most applicable?1) Collection2) Set3) SortedSet4) MapQ21What does the value returned by the method getID() found in class java.awt.AWTEvent uniquely identify?1) The particular event instance.2) The source of the event.3) The set of events that were triggered by the same action.4) The type of event.5) The type of component from which the event originated.Q22What will be written to the standard output when the following program is run?class Base {int i;Base() {add(1);}void add(int v) {i += v;}void print() {System.out.println(i);}}class Extension extends Base {Extension() {add(2);}void add(int v) {i += v*2;}}public class Qd073 {public static void main(String args[]) {bogo(new Extension());}static void bogo(Base b) {b.add(8);b.print();}}1) 92) 183) 204) 215) 22Q23Which lines of code are valid declarations of a native method when occurring within the declaration of the following class?public class Qf575 {// insert declaration of a native method here}1) native public void setTemperature(int kelvin);2) private native void setTemperature(int kelvin);3) protected int native getTemperature();4) public abstract native void setTemperature(int kelvin);5) native int setTemperature(int kelvin) {}Q24How does the weighty property of the GridBagConstraints objects used in grid bag layout affect the layout of the components?1) It affects which grid cell the components end up in.2) It affects how the extra vertical space is distributed.3) It affects the alignment of each component.4) It affects whether the components completely fill their allotted display area vertically.Q25Which statements can be inserted at the indicated position in the following code to make the program write 1 on the standard output when run?public class Q4a39 {int a = 1;int b = 1;int c = 1;class Inner {int a = 2;int get() {int c = 3;// insert statement herereturn c;}}Q4a39() {Inner i = new Inner();System.out.println(i.get());}public static void main(String args[]) {new Q4a39();}}1) c = b;2) c = this.a;3) c = this.b;4) c = Q4a39.this.a;5) c = c;Q26Which is the earliest line in the following code after which the object created on the line marked (0) will be a candidate for being garbage collected, assuming no compiler optimizations are done?public class Q76a9 {static String f() {String a = "hello";String b = "bye"; // (0)String c = b + "!"; // (1)String d = b;b = a; // (2)d = a; // (3)return c; // (4)}public static void main(String args[]) {String msg = f();System.out.println(msg); // (5)}}1) The line marked (1).2) The line marked (2).3) The line marked (3).4) The line marked (4).5) The line marked (5).Q27Which methods from the String and StringBuffer classes modify the object on which they are called?1) The charAt() method of the String class.2) The toUpperCase() method of the String class.3) The replace() method of the String class.4) The reverse() method of the StringBuffer class.5) The length() method of the StringBuffer class.Q28Which statements, when inserted at the indicated position in the following code, will cause a runtime exception when attempting to run the program?class A {}class B extends A {}class C extends A {}public class Q3ae4 {public static void main(String args[]) {A x = new A();B y = new B();C z = new C();// insert statement here}}1) x = y;2) z = x;3) y = (B) x;4) z = (C) y;5) y = (A) y;Q29Which of these are keywords in Java?1) default2) NULL3) String4) throws5) longQ30It is desirable that a certain method within a certain class can only be accessed by classes that are defined within the same package as the class of the method. How can such restrictions be enforced?1) Mark the method with the keyword public.2) Mark the method with the keyword protected.3) Mark the method with the keyword private.4) Mark the method with the keyword package.5) Do not mark the method with any accessibility modifiers.Q31Which code fragments will succeed in initializing a two-dimensional array named tab with a size that will cause the expression tab[3][2] to access a valid element?CODE FRAGMENT A:int[][] tab = {{ 0, 0, 0 },{ 0, 0, 0 }};CODE FRAGMENT B:int tab[][] = new int[4][];for (int i=0; iCODE FRAGMENT C:int tab[][] = {0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0};CODE FRAGMENT D:int tab[3][2];CODE FRAGMENT E:int[] tab[] = { {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0} };1) Code fragment A.2) Code fragment B.3) Code fragment C.4) Code fragment D.5) Code fragment E.Q32What will be the result of attempting to run the following program?public class Qaa75 {public static void main(String args[]) {String[][][] arr = {{ {}, null },{ { "1", "2" }, { "1", null, "3" } },{},{ { "1", null } }};System.out.println(arr.length + arr[1][2].length);}}1) The program will terminate with an ArrayIndexOutOfBoundsException.2) The program will terminate with a NullPointerException.3) 4 will be written to standard output.4) 6 will be written to standard output.5) 7 will be written to standard output.Q33Which expressions will evaluate to true if preceded by the following code?String a = "hello";String b = new String(a);String c = a;char[] d = { 'h', 'e', 'l', 'l', 'o' };1) (a == "Hello")2) (a == b)3) (a == c)4) a.equals(b)5) a.equals(d)Q34Which statements concerning the following code are true?class A {public A() {}public A(int i) { this(); }}class B extends A {public boolean B(String msg) { return false; }}class C extends B {private C() { super(); }public C(String msg) { this(); }public C(int i) {}}1) The code will fail to compile.2) The constructor in A that takes an int as an argument will never be called as a result of constructing an object of class B or C.3) Class C has three constructors.4) Objects of class B cannot be constructed.5) At most one of the constructors of each class is called as a result of constructing an object of class C.Q35Given two collection objects referenced by col1 and col2, which of these statements are true?1) The operation col1.retainAll(col2) will not modify the col1 object.2) The operation col1.removeAll(col2) will not modify the col2 object.3) The operation col1.addAll(col2) will return a new collection object,containing elements from both col1 and col2.4) The operation col1.containsAll(Col2) will not modify the col1 object.Q36Which statements concerning the relationships between the following classes are true?class Foo {int num;Baz comp = new Baz();}class Bar {boolean flag;}class Baz extends Foo {Bar thing = new Bar();double limit;}1) A Bar is a Baz.2) A Foo has a Bar.3) A Baz is a Foo.4) A Foo is a Baz.5) A Baz has a Bar.Q37Which statements concerning the value of a member variable are true, when no explicit assignments have been made?1) The value of an int is undetermined.2) The value of all numeric types is zero.3) The compiler may issue an error if the variable is used before it is initialized.4) The value of a String variable is "" (empty string).5) The value of all object variables is null.Q38Which statements describe guaranteed behavior of the garbage collection and finalization mechanisms?1) Objects are deleted when they can no longer be accessed through any reference.2) The finalize() method will eventually be called on every object.3) The finalize() method will never be called more than once on an object.4) An object will not be garbage collected as long as it is possible for an active part of the program to access it through a reference.5) The garbage collector will use a mark and sweep algorithm.Q39Which code fragments will succeed in printing the last argument given on the command line to the standard output, and exit gracefully with no output if no arguments are given?CODE FRAGMENT A:public static void main(String args[]) {if (args.length != 0)System.out.println(args[args.length-1]);}CODE FRAGMENT B:public static void main(String args[]) {try { System.out.println(args[args.length]); }catch (ArrayIndexOutOfBoundsException e) {}}CODE FRAGMENT C:public static void main(String args[]) {int ix = args.length;String last = args[ix];if (ix != 0) System.out.println(last);}CODE FRAGMENT D:public static void main(String args[]) {int ix = args.length-1;if (ix > 0) System.out.println(args[ix]);}CODE FRAGMENT E:public static void main(String args[]) {try { System.out.println(args[args.length-1]); }catch (NullPointerException e) {}}1) Code fragment A.2) Code fragment B.3) Code fragment C.4) Code fragment D.5) Code fragment E.Q40Which of these statements concerning the collection interfaces are true?1) Set extends Collection.2) All methods defined in Set are also defined in Collection.3) List extends Collection.4) All methods defined in List are also defined in Collection.5) Map extends Collection.Q41What is the name of the method that threads can use to pause their execution until signalled to continue by another thread?Fill in the name of the method (do not include a parameter list).Q42Given the following class definitions, which expression identifies whether the object referred to by obj was created by instantiating class B rather than classes A, C and D?class A {}class B extends A {}class C extends B {}class D extends A {}1) obj instanceof B2) obj instanceof A && ! (obj instanceof C)3) obj instanceof B && ! (obj instanceof C)4) obj instanceof C || obj instanceof D5) (obj instanceof A) && ! (obj instanceof C) && ! (obj instanceof D)Q43What will be written to the standard output when the following program is run?public class Q8499 {public static void main(String args[]) {double d = -2.9;int i = (int) d;i *= (int) Math.ceil(d);i *= (int) Math.abs(d);System.out.println(i);}}1) 122) 183) 84) 125) 27Q44What will be written to the standard output when the following program is run?public class Qcb90 {int a;int b;public void f() {a = 0;b = 0;int[] c = { 0 };g(b, c);System.out.println(a + " " + b + " " + c[0] + " ");}public void g(int b, int[] c) {a = 1;b = 1;c[0] = 1;}public static void main(String args[]) {Qcb90 obj = new Qcb90();obj.f();}}1) 0 0 02) 0 0 13) 0 1 04) 1 0 05) 1 0 1Q45Which statements concerning the effect of the statement gfx.drawRect(5, 5, 10, 10) are true, given that gfx is a reference to a valid Graphics object?1) The rectangle drawn will have a total width of 5 pixels.2) The rectangle drawn will have a total height of 6 pixels.3) The rectangle drawn will have a total width of 10 pixels.4) The rectangle drawn will have a total height of 11 pixels.Q46Given the following code, which code fragments, when inserted at the indicated location, will succeed in making the program display a button spanning the whole window area?import java.awt.*;public class Q1e65 {public static void main(String args[]) {Window win = new Frame();Button but = new Button("button");// insert code fragment herewin.setSize(200, 200);win.setVisible(true);}}1) win.setLayout(new BorderLayout()); win.add(but);2) win.setLayout(new GridLayout(1, 1)); win.add(but);3) win.setLayout(new BorderLayout()); win.add(but, BorderLayout.CENTER);4) win.add(but);5) win.setLayout(new FlowLayout()); win.add(but);Q47Which method implementations will write the given string to a file named "file", using UTF8 encoding?IMPLEMENTATION A:public void write(String msg) throws IOException {FileWriter fw = new FileWriter(new File("file"));fw.write(msg);fw.close();}IMPLEMENTATION B:public void write(String msg) throws IOException {OutputStreamWriter osw =new OutputStreamWriter(new FileOutputStream("file"), "UTF8");osw.write(msg);osw.close();}IMPLEMENTATION C:public void write(String msg) throws IOException { FileWriter fw = new FileWriter(new File("file"));fw.setEncoding("UTF8");fw.write(msg);fw.close();}IMPLEMENTATION D:public void write(String msg) throws IOException { FilterWriter fw = FilterWriter(new FileWriter("file"), "UTF8"); fw.write(msg);fw.close();}IMPLEMENTATION E:public void write(String msg) throws IOException { OutputStreamWriter osw = new OutputStreamWriter(new OutputStream(new File("file")), "UTF8");osw.write(msg);osw.close();}1) Implementation A.2) Implementation B.3) Implementation C.4) Implementation D.5) Implementation E.Q48Which are valid identifiers?1) _class2) $value$3) zer@4) ¥ngstr5) 2muchuqQ49What will be the result of attempting to compile and run the following program?public class Q28fd {public static void main(String args[]) {int counter = 0;l1:for (int i=10; i<0; i--) {l2:int j = 0;while (j < 10) {if (j > i) break l2;if (i == j) {counter++;continue l1;}}counter--;}System.out.println(counter);}}1) The program will fail to compile.2) The program will not terminate normally.3) The program will write 10 to the standard output.4) The program will write 0 to the standard output.5) The program will write 9 to the standard output.Q50Given the following interface definition, which definitions are valid?interface I {void setValue(int val);int getValue();}DEFINITION A:(a) class A extends I {int value;void setValue(int val) { value = val; }int getValue() { return value; }}DEFINITION B:(b) interface B extends I {void increment();}DEFINITION C:(c) abstract class C implements I {int getValue() { return 0; }abstract void increment();}DEFINITION D:(d) interface D implements I {void increment();}DEFINITION E:(e) class E implements I {int value;public void setValue(int val) { value = val; } }1) Definition A.2) Definition B.3) Definition C.4) Definition D.5) Definition E.Q51Which statements concerning the methods notify() and notifyAll() are true?1) Instances of class Thread have a method called notify().2) A call to the method notify() will wake the thread that currently owns the monitor of the object.3) The method notify() is synchronized.4) The method notifyAll() is defined in class Thread.5) When there is more than one thread waiting to obtain the monitor of an object, there is no way to be sure which thread will be notified by the notify() method.Q52Which statements concerning the correlation between the inner and outer instances of non-static inner classes are true?1) Member variables of the outer instance are always accessible to inner instances, regardless of their accessibility modifiers.2) Member variables of the outer instance can never be referred to using only the variable name within the inner instance.3) More than one inner instance can be associated with the same outer instance.4) All variables from the outer instance that should be accessible in the inner instance must be declared final.5) A class that is declared final cannot have any inner classes.Q53What will be the result of attempting to compile and run the following code?public class Q6b0c {public static void main(String args[]) {int i = 4;float f = 4.3;double d = 1.8;int c = 0;if (i == f) c++;if (((int) (f + d)) == ((int) f + (int) d)) c += 2;System.out.println(c);}}1) The code will fail to compile.2) 0 will be written to the standard output.3) 1 will be written to the standard output.4) 2 will be written to the standard output.5) 3 will be written to the standard output.Q54Which operators will always evaluate all the operands?1) ||2) +3) &&4) ? :5) %Q55Which statements concerning the switch construct are true?1) All switch statements must have a default label.2) There must be exactly one label for each code segment in a switch statement.3) The keyword continue can never occur within the body of a switch statement.4) No case label may follow a default label within a single switch statement.5) A character literal can be used as a value for a case label.Q56Which modifiers and return types would be valid in the declaration of a working main() method for a Java standalone application?1) private2) final3) static4) int5) abstractQ57What will be the appearance of an applet with the following init() method?public void init() {add(new Button("hello"));}1) Nothing appears in the applet.2) A button will cover the whole area of the applet.3) A button will appear in the top left corner of the applet.4) A button will appear, centered in the top region of the applet.5) A button will appear in the center of the applet.Q58Which statements concerning the event model of the AWT are true?1) At most one listener of each type can be registered with a component.2) Mouse motion listeners can be registered on a List instance.3) There exists a class named ContainerEvent in package java.awt.event.4) There exists a class named MouseMotionEvent in package java.awt.event.5) There exists a class named ActionAdapter in package java.awt.event.Q59Which statements are true, given the code new FileOutputStream("data", true) for creating an object of class FileOutputStream?1) FileOutputStream has no constructors matching the given arguments.2) An IOExeception will be thrown if a file named "data" already exists.3) An IOExeception will be thrown if a file named "data" does not already exist.4) If a file named "data" exists, its contents will be reset and overwritten.5) If a file named "data" exists, output will be appended to its current contents.Q60Given the following code, write a line of code that, when inserted at the indicated location, will make the overriding method in Extension invoke the overridden method in class Base on the current object.class Base {public void print() {System.out.println("base");}}class Extention extends Base {public void print() {System.out.println("extension");// insert line of implementation here}}public class Q294d {public static void main(String args[]) {Extention ext = new Extention();ext.print();}}Fill in a single line of implementation.Q61Given that file is a reference to a File object that represents a directory, which code fragments will succeed in obtaining a list of the entries in the directory?1) Vector filelist = ((Directory) file).getList();2) String[] filelist = file.directory();3) Enumeration filelist = file.contents();4) String[] filelist = file.list();5) Vector filelist = (new Directory(file)).files();Q62。

SCJP题库

SCJP题库

yModule 1-JAVA 基础一、选择题:Question 1Given:35. String #name = "Jane Doe";36. int $age=24;37. Double _height = 123.5;38. double ~temp = 37.5;Which two are true? (Choose two.)A. Line 35 will not compile.B. Line 36 will not compile.C. Line 37 will not compile.D. Line 38 will not compile.Answer: AD 标识符以字母,下划线,或者$开始Question 2Given:11. public class Test {12. public static void main(String [] args) {13. int x =5;14. boolean b1 = true;15. boolean b2 = false;16.17.if((x==4) && !b2)18. System.out.print("l ");19. System.out.print("2 ");20. if ((b2 = true) && b1)21. System.out.print("3");22. }23. }What is the result?A. 2B. 3C. 1 2D. 2 3E. 1 2 3F. Compilation fails.G. An exceptional is thrown at runtime.Answer: D 注意20行,=为赋值,不要被骗Question 3Given:42. public class ClassA {43. public int getValue() {44. int value=0;45. boolean setting = true;46. String title="Hello";47. if (value || (setting && title == "Hello")) { return 1; }48. if (value == 1 & title.equals("Hello")) { return 2; }49. }50. }And:70. ClassA a = new ClassA();71. a.getValue();What is the result?A. 1B. 2C. Compilation fails.D. The code runs with no output.E. An exception is thrown at runtime.Answer: C 编译不通过,47行value为int类型不是booleanQuestion 4Given:11. public void testIfA() {12. if(testIfB("True")) {13. System.out.println("True");14. } else {15. System.out.println("Not true");16. }17. }18. public Boolean testIfB(String str) {19. return Boolean.valueOf(str);20. }What is the result when method testIfA is invoked?A. TrueB. Not trueC. An exception is thrown at runtime.D. Compilation fails because of an error at line 12.E. Compilation fails because of an error at line 19. Answer: A 19行,如果str为true则返回ture,否则返回falseQuestion 5Given:11. public static void main(String[] args) {12. Integer i = new Integer(1) + new Integer(2);13. switch(i) {14. case 3: System.out.println("three"); break;15. default: System.out.println("other"); break;16. }17. }What is the result?A. threeB. otherC. An exception is thrown at runtime.D. Compilation fails because of an error on line 12.E. Compilation fails because of an error on line 13.F. Compilation fails because of an error on line 15. Answer: A 就是两个Integer类型相加Question 6Given:11. public static void main(String[] args) {12. String str = "null";13. if (str == null) {14. System.out.println("null");15. } else (str.length() == 0) {16. System.out.println("zero");17. } else {18. System.out.println("some");19. }20. }‘What is the result?A. nullB. zeroC. someD. Compilation fails.E. An exception is thrown at runtime. Answer: D 这题真恶心 15行少个ifQuestion 7Given:10.int x=0;11.int y=10;12. do {l3. y--;14. ++x;15. } while (x < 5);16. System.out.print(x + "," + y);What is the result?A. 5,6B. 5,5C. 6,5D. 6,6Answer: B (91,82,73,64,55)没啥争议Question 8Given:25.int x=12;26. while (x < 10) {27. x--;28. }29. System.out.print(x);What is the result?A. 0B. 10C. 12D. Line 29 will never be reached. Answer: C 12>10,所以直接跳出循环,输出x=12 Question 9Given:35. int x= 10;36. do {37. x--;38. } while(x< 10);How many times will line 37 be executed?A. ten timesB. zero timesC. one to me timesD. more than ten timesAnswer: D 死循环Question 10Given:11. public static void main(String[] args) {12. for (int i=0;i<= 10;i++){13. if( i>6) break;14. }15. System.out.println(i);16. }What is the result?A. 6B. 7C. 10D. 11E. Compilation fails.F. An exception is thrown at runtime.Answer: E 15行i超出了作用域Question 11Given:55. int []x= {1, 2,3,4, 5};56. int y[] =x;57. System.out.println(y[2]);Which is true?A. Line 57 will print the value 2.B. Line 57 will print the value 3.C. Compilation will fail because of an error in line 55.D. Compilation will fail because of an error in line 56.Answer: B 没争议,考察数组下标是从0开始Question 12Which two code fragments(片段) correctly(正确) create and initialize a static array of int elements? (Choose two.)A. static final int[] a = { 100,200 };B. static final int[] a;static { a=new int[2]; a[0]=100; a[1]=200; }C. static final int[] a = new int[2] { 100,200 };D. static final int[] a;static void init() { a = new int[3]; a[0]=100; a[1]=200; }Answer: AB c不能指定长度,d不能在init方法中赋值,要么在static代码块中Question 13Given:11. public static void main(String[] args) {12. Object obj = new int[] { 1,2,3 };13. int[] someArray = (int[])obj;14. for (int i: someArray) System.out.print(i +" ")15. }‘What is the result?A. 1 2 3B. Compilation fails because of an error in line 12.C. Compilation fails because of an error in line 13.D. Compilation fails because of an error in line 14.E. A ClassCastException is thrown at runtime.Answer: A 没争议,foeach循环遍历数组Question 14Given:11. String[] elements = { "for", "tea", "too" };12. String first = (elements.length > 0)? elements[0] : null;What is the result?A. Compilation fails.B. An exception is thrown at runtime.C. The variable first is set to null.D. The variable first is set to elements[0].Answer: DQuestion 15Given:10. public class Bar {11.static void foo(int...x) {12. // insert code here13. }14. }Which two code fragments, inserted independently(独立的) at line 12, will allow the class to compile? (Choose two.)A. foreach(x) System.out.println(z);B. for(int z : x) System.out.println(z);C. while( x.hasNext()) System.out.println( x.next());D. for( int i=0; i< x.length; i++ ) System.out.println(x[i]); Answer: BD x相当于一个数组,a明显错没有foreach,c中x没有hadNext方法Question 16A programmer(程序员) needs to create a logging method that can accept (接受) an arbitrary(随意任意) number of arguments. For example, it may be called in theseways:logIt("log message 1 ");logIt("log message2”,”log message3");logIt("log message4", "log message5", "log message6");Which declaration(说明) satisfies(符合) this requirement(需求)?A. public void logIt(String * msgs)B. public void logIt(String [] msgs)C. public void logIt(String... msgs)D. public void logIt(String msg1, String msg2, String msg3)Answer: C 可变长参数Question 171. public class A {2. public String doit(int x, int y) {3. return "a";4. }5.6. public String doit(int... vals) {7. return "b";8. }9. }Given:25. A a=new A();26. System.out.println(a.doit(4, 5));What is the result?A. Line 26 prints "a" to System.out.B. Line 26 prints "b" to System.out.C. An exception is thrown at line 26 at runtime.D. Compilation of class A will fail due to an error in line 6. Answer: A 确定参数和可变长参数同时存在的时候,优先考虑确定参数的Question 18Given a file GrizzlyBear.java:1. package animals.mammals;2.3. public class GrizzlyBear extends Bear {4. void hunt() {5. Salmon s = findSalmon();6. s.consume();7. }8. }and another file, Salmon.java:1. package animals.fish;2.3. public class Salmon extends Fish {4. void consume() { /* do stuff */ }5. }Assume(假定) both classes are defined in the correct directories for theft packages, and that the Mammal class correctly defines the findSalmon() method. Which two changes allow this code to compile correctly? (Choose two.)A. add public to the start of line 4 in Salmon.javaB. add public to the start of line 4 in GrizzlyBear.javaC. add import animals.mammals.*; at line 2 in Salmon.javaD. add import animals.fish.*; at line 2 in GrizzlyBear.javaE. add import animals.fish.Salmon.*; at line 2 in GrizzlyBear.javaF. add import animals.mammals.GrizzlyBear.*;at line 2 in Salmon.java Answer: AD 调用不同包下的类,要先导入,方法权限要设置成publicQuestion 19Given:10. package com.sun.scjp;11. public class Geodetics {12. public static final double DIAMETER = 12756.32; // kilometers13. }Which two correctly access(访问) the DIAMETER member of the Geodetics class? (Choose two.)A. import com.sun.scjp.Geodetics;public class TerraCarta {public double halfway(){ return Geodetics.DIAMETER/2.0; } }B. import static com.sun.scjp.Geodetics;public class TerraCarta {public double halfway() { return DIAMETER/2.0; } }C. import static com.sun.scjp.Geodetics. *;public class TerraCarta {public double halfway() { return DIAMETER/2.0; } }D. package com.sun.scjp;public class TerraCarta {public double halfway() { return DIAMETER/2.0; } }Answer: AC b中不能静态导入类,c中静态导入类属性,正确,d访问错误很明显Question 20Given classes defined in two different files:1. package util;2. public class BitUtils {3. private static void process(byte[] b) { }4. }1. package app;2. public class SomeApp {3. public static void main(String[] args) {4. byte[] bytes = new byte[256];5. // insert code here6. }7. }What is required(必需的) at line 5 in class SomeApp to use the process methodof BitUtils?A. process(bytes);B. BitUtils.process(bytes);C. app.BitUtils.process(bytes);D. util.BitUtils.process(bytes);E. import util.BitUtils. *; process(bytes);F. SomeApp cannot use the process method in BitUtils.Answer: F 私有的,不能被访问Question 21Given a class Repetition(重复):1. package utils;2.3. public class Repetition {4. public static String twice(String s) { return s + s; }5. }and given another class Demo:1. // insert code here2.3. public class Demo {4. public static void main(String[] args) {5. System.out.println(twice("pizza"));6. }7. }Which code should be inserted at line 1 of Demo.java to compile and run Demo to print “pizzapizza”?A. import utils.*;B. static import utils.*;C. import utils.Repetition.*;D. static import utils.Repetition. *;E. import utils.Repetition.twice();F. import static utils.Repetition.twice;G. static import utils.Repetition.twice;Answer: F 静态导入Question 22Given:1. package test;2.3. class Target(目标) {4. public String name = "hello";5. }What can directly(直接的) access and change the value of the variable (变量) name?A. any classB. only the Target classC. any class in the test packageD. any class that extends TargetAnswer: C default类型的类本包访问权限Question 23Given:11. rbo = new ReallyBigObject();12. // more code here13. rbo = null;14. /* insert code here */Which statement(语句) should be placed at line 14 to suggest(促成) that the virtual machine(虚拟机) expend(消耗) effort(努力) toward recycling (回收) the memory used by the object rbo?A. System.gc();B. Runtime.gc();C. System.freeMemory();D. Runtime.getRuntime().growHeap();E. Runtime.getRuntime().freeMemory();Answer: A 题很简单。

SCJP

SCJP

1.Given:1. public class returnIt {2. returnType methodA(byte x, double y){3. return (short) x/y * 2;4. }5. }What is the valid returnType for methodA in line 2?A. intB. byteC. longD. shortE. floatF. doubleAnswer F注释:short类型的x,除以double类型的y,再乘int的2,所以结果是double类型的。

注意第三行的强制转换,只是转换了x。

2.1) class Super{2) public float getNum(){return 3.0f;}3) }4)5) public class Sub extends Super{6)7) }which method, placed at line 6, will cause a compiler error?A. public float getNum(){return 4.0f;}B. public void getNum(){}C. public void getNum(double d){}D. public double getNum(float d){return 4.0d;}Answer :B注意这道题主要考的是方法的overload和override。

对于overload,只有参数列表不同,才做为标准,而返回值和访问控制关键字不能做为标准,所以B错在方法名相同,但只有返回值不同,这是错的。

C和D是正确的overload。

对于override,则访问控制关键字只能更加公有化,异常只能是超类方法抛出的异常的子类,也可以不抛出。

返回类型,参数列表必须精确匹配。

所以A是正确的override。

3.1)public class Foo{2) public static void main(String args[]){3) try{return;}4) finally{ System.out.println("Finally");}5) }6) }what is the result?A. The program runs and prints nothing.B. The program runs and prints “Finally”.C. The code compiles, but an exception is thrown at runtime.D. The code will not compile because the catch block is missing.Answer:btry......catch......finally的问题。

SCJP题库之欧阳文创编

SCJP题库之欧阳文创编

yModule 1-JAVA 基础一、选择题:Question 1Given:35. String #name = "Jane Doe";36. int $age=24;37. Double _height = 123.5;38. double ~temp = 37.5;Which two are true? (Choose two.)A. Line 35 will not compile.B. Line 36 will not compile.C. Line 37 will not compile.D. Line 38 will not compile.Answer: AD 标识符以字母,下划线,或者$开始Question 2Given:11. public class Test {12. public static void main(String [] args) {13. int x =5;14. boolean b1 = true;15. boolean b2 = false;16.17.if((x==4) && !b2)18. System.out.print("l ");19. System.out.print("2 ");20. if ((b2 = true) && b1)21. System.out.print("3");22. }23. }What is the result?A. 2B. 3C. 1 2D. 2 3E. 1 2 3F. Compilation fails.G. An exceptional is thrown at runtime.Answer: D 注意20行,=为赋值,不要被骗Question 3Given:42. public class ClassA {43. public int getValue() {44. int value=0;45. boolean setting = true;46. String title="Hello";47. if (value || (setting && title == "Hello")) { return 1; }48. if (value == 1 & title.equals("Hello")) { return 2; }49. }50. }And:70. ClassA a = new ClassA();71. a.getValue();What is the result?A. 1B. 2C. Compilation fails.D. The code runs with no output.E. An exception is thrown at runtime.Answer: C 编译不通过,47行value为int类型不是boolean Question 4Given:11. public void testIfA() {12. if(testIfB("True")) {13. System.out.println("True");14. } else {15. System.out.println("Not true");16. }17. }18. public Boolean testIfB(String str) {19. return Boolean.valueOf(str);20. }What is the result when method testIfA is invoked?A. TrueB. Not trueC. An exception is thrown at runtime.D. Compilation fails because of an error at line 12.E. Compilation fails because of an error at line 19. Answer: A 19行,如果str为true则返回ture,否则返回false Question 5Given:11. public static void main(String[] args) {12. Integer i = new Integer(1) + new Integer(2);13. switch(i) {14. case 3: System.out.println("three"); break;15. default: System.out.println("other"); break;16. }17. }What is the result?A. threeB. otherC. An exception is thrown at runtime.D. Compilation fails because of an error on line 12.E. Compilation fails because of an error on line 13.F. Compilation fails because of an error on line 15. Answer: A 就是两个Integer类型相加Question 6Given:11. public static void main(String[] args) {12. String str = "null";13. if (str == null) {14. System.out.println("null");15. } else (str.length() == 0) {16. System.out.println("zero");17. } else {18. System.out.println("some");19. }20. }‘What is the resul t?C. someD. Compilation fails.E. An exception is thrown at runtime. Answer: D 这题真恶心 15行少个ifQuestion 7Given:10.int x=0;11.int y=10;12. do {l3. y--;14. ++x;15. } while (x < 5);16. System.out.print(x + "," + y);What is the result?A. 5,6B. 5,5C. 6,5D. 6,6Answer: B (91,82,73,64,55)没啥争议Question 8Given:25.int x=12;26. while (x < 10) {27. x--;28. }29. System.out.print(x);What is the result?A. 0B. 10C. 12D. Line 29 will never be reached.Answer: C 12>10,所以直接跳出循环,输出x=12 Question 9Given:35. int x= 10;38. } while(x< 10);How many times will line 37 be executed?A. ten timesB. zero timesC. one to me timesD. more than ten timesAnswer: D 死循环Question 10Given:11. public static void main(String[] args) {12. for (int i=0;i<= 10;i++){13. if( i>6) break;14. }15. System.out.println(i);16. }What is the result?A. 6B. 7C. 10D. 11E. Compilation fails.F. An exception is thrown at runtime.Answer: E 15行i超出了作用域Question 11Given:55. int []x= {1, 2,3,4, 5};56. int y[] =x;57. System.out.println(y[2]);Which is true?A. Line 57 will print the value 2.B. Line 57 will print the value 3.C. Compilation will fail because of an error in line 55.D. Compilation will fail because of an error in line 56. Answer: B 没争议,考察数组下标是从0开始Question 12Which two code fragments(片段)correctly(正确)create and initialize a static array of int elements? (Choose two.)A. static final int[] a = { 100,200 };B. static final int[] a;static { a=new int[2]; a[0]=100; a[1]=200; }C. static final int[] a = new int[2] { 100,200 };D. static final int[] a;static void init() { a = new int[3]; a[0]=100; a[1]=200; } Answer: AB c不能指定长度,d不能在init方法中赋值,要么在static 代码块中Question 13Given:11. public static void main(String[] args) {12. Object obj = new int[] { 1,2,3 };13. int[] someArray = (int[])obj;14. for (int i: someArray) System.out.print(i +" ")15. }‘What is the result?A. 1 2 3B. Compilation fails because of an error in line 12.C. Compilation fails because of an error in line 13.D. Compilation fails because of an error in line 14.E. A ClassCastException is thrown at runtime.Answer: A 没争议,foeach循环遍历数组Question 14Given:11. String[] elements = { "for", "tea", "too" };12. String first = (elements.length > 0)? elements[0] : null;What is the result?A. Compilation fails.B. An exception is thrown at runtime.C. The variable first is set to null.D. The variable first is set to elements[0].Answer: DQuestion 15Given:10. public class Bar {11.static void foo(int...x) {12. // insert code here13. }14. }Which two code fragments, inserted independently(独立的)at line 12, will allow the class to compile? (Choose two.)A. foreach(x) System.out.println(z);B. for(int z : x) System.out.println(z);C. while( x.hasNext()) System.out.println( x.next());D. for( int i=0; i< x.length; i++ ) System.out.println(x[i]); Answer: BD x相当于一个数组,a明显错没有foreach,c中x没有hadNext方法Question 16A programmer(程序员) needs to create a logging method that can accept(接受) an arbitrary(随意任意) number of arguments. For example, it may be called in theseways:logIt("log message 1 ");logIt("log message2”,”log message3");logIt("log message4", "log message5", "log message6");Which declaration(说明) satisfies(符合) this requirement(需求)?A. public void logIt(String * msgs)B. public void logIt(String [] msgs)C. public void logIt(String... msgs)D. public void logIt(String msg1, String msg2, String msg3) Answer: C 可变长参数Question 171. public class A {2. public String doit(int x, int y) {3. return "a";4. }5.6. public String doit(int... vals) {7. return "b";8. }9. }Given:25. A a=new A();26. System.out.println(a.doit(4, 5));What is the result?A. Line 26 prints "a" to System.out.B. Line 26 prints "b" to System.out.C. An exception is thrown at line 26 at runtime.D. Compilation of class A will fail due to an error in line 6. Answer: A 确定参数和可变长参数同时存在的时候,优先考虑确定参数的Question 18Given a file GrizzlyBear.java:1. package animals.mammals;2.3. public class GrizzlyBear extends Bear {4. void hunt() {5. Salmon s = findSalmon();6. s.consume();7. }8. }and another file, Salmon.java:1. package animals.fish;2.3. public class Salmon extends Fish {4. void consume() { /* do stuff */ }5. }Assume(假定) both classes are defined in the correct directories for theft packages, and that the Mammal class correctly defines the findSalmon() method. Which two changes allow this code to compile correctly? (Choose two.)A. add public to the start of line 4 in Salmon.javaB. add public to the start of line 4 in GrizzlyBear.javaC. add import animals.mammals.*; at line 2 in Salmon.javaD. add import animals.fish.*; at line 2 in GrizzlyBear.javaE. add import animals.fish.Salmon.*; at line 2 in GrizzlyBear.javaF. add import animals.mammals.GrizzlyBear.*;at line 2 in Salmon.javaAnswer: AD 调用不同包下的类,要先导入,方法权限要设置成public Question 19Given:10. package com.sun.scjp;11. public class Geodetics {12. public static final double DIAMETER = 12756.32; // kilometers13. }Which two correctly access(访问) the DIAMETER member of the Geodetics class? (Choose two.)A. import com.sun.scjp.Geodetics;public class TerraCarta {public double halfway(){ return Geodetics.DIAMETER/2.0; } }B. import static com.sun.scjp.Geodetics;public class TerraCarta {public double halfway() { return DIAMETER/2.0; } }C. import static com.sun.scjp.Geodetics. *;public class TerraCarta {public double halfway() { return DIAMETER/2.0; } }D. package com.sun.scjp;public class TerraCarta {public double halfway() { return DIAMETER/2.0; } }Answer: AC b中不能静态导入类,c中静态导入类属性,正确,d访问错误很明显Question 20Given classes defined in two different files:1. package util;2. public class BitUtils {3. private static void process(byte[] b) { }4. }1. package app;2. public class SomeApp {3. public static void main(String[] args) {4. byte[] bytes = new byte[256];5. // insert code here6. }7. }What is required(必需的) at line 5 in class SomeApp to use the process methodof BitUtils?A. process(bytes);B. BitUtils.process(bytes);C. app.BitUtils.process(bytes);D. util.BitUtils.process(bytes);E. import util.BitUtils. *; process(bytes);F. SomeApp cannot use the process method in BitUtils.Answer: F 私有的,不能被访问Question 21Given a class Repetition(重复):1. package utils;2.3. public class Repetition {4. public static String twice(String s) { return s + s; }5. }and given another class Demo:1. // insert code here2.3. public class Demo {4. public static void main(String[] args) {5. System.out.println(twice("pizza"));6. }7. }Which code should be inserted at line 1 of Demo.java to compile and run Demo to print “pizzapizza”?A. import utils.*;B. static import utils.*;C. import utils.Repetition.*;D. static import utils.Repetition. *;E. import utils.Repetition.twice();F. import static utils.Repetition.twice;G. static import utils.Repetition.twice;Answer: F 静态导入Question 22Given:1. package test;2.3. class Target(目标) {4. public String name = "hello";5. }What can directly(直接的)access and change the value of the variable(变量) name?A. any classB. only the Target classC. any class in the test packageD. any class that extends TargetAnswer: C default类型的类本包访问权限Question 23Given:11. rbo = new ReallyBigObject();12. // more code here13. rbo = null;14. /* insert code here */Which statement(语句)should be placed at line 14 to suggest (促成) that the virtual machine(虚拟机) expend(消耗) effort (努力) toward recycling(回收) the memory used by the object rbo?A. System.gc();B. Runtime.gc();C. System.freeMemory();D. Runtime.getRuntime().growHeap();E. Runtime.getRuntime().freeMemory();Answer: A 题很简单。

SCJP题库之欧阳理创编

SCJP题库之欧阳理创编

yModule 1-JAVA 基础一、选择题:Question 1Given:35. String #name = "Jane Doe";36. int $age=24;37. Double _height = 123.5;38. double ~temp = 37.5;Which two are true? (Choose two.)A. Line 35 will not compile.B. Line 36 will not compile.C. Line 37 will not compile.D. Line 38 will not compile.Answer: AD 标识符以字母,下划线,或者$开始Question 2Given:11. public class Test {12. public static void main(String [] args) {13. int x =5;14. boolean b1 = true;15. boolean b2 = false;16.17.if((x==4) && !b2)18. System.out.print("l ");19. System.out.print("2 ");20. if ((b2 = true) && b1)21. System.out.print("3");22. }23. }What is the result?A. 2B. 3C. 1 2D. 2 3E. 1 2 3F. Compilation fails.G. An exceptional is thrown at runtime.Answer: D 注意20行,=为赋值,不要被骗Question 3Given:42. public class ClassA {43. public int getValue() {44. int value=0;45. boolean setting = true;46. String title="Hello";47. if (value || (setting && title == "Hello")) { return 1; }48. if (value == 1 & title.equals("Hello")) { return 2; }49. }50. }And:70. ClassA a = new ClassA();71. a.getValue();What is the result?A. 1B. 2C. Compilation fails.D. The code runs with no output.E. An exception is thrown at runtime.Answer: C 编译不通过,47行value为int类型不是booleanQuestion 4Given:11. public void testIfA() {12. if(testIfB("True")) {13. System.out.println("True");14. } else {15. System.out.println("Not true");16. }17. }18. public Boolean testIfB(String str) {19. return Boolean.valueOf(str);20. }What is the result when method testIfA is invoked?A. TrueB. Not trueC. An exception is thrown at runtime.D. Compilation fails because of an error at line 12.E. Compilation fails because of an error at line 19. Answer: A 19行,如果str为true则返回ture,否则返回falseQuestion 5Given:11. public static void main(String[] args) {12. Integer i = new Integer(1) + new Integer(2);13. switch(i) {14. case 3: System.out.println("three"); break;15. default: System.out.println("other"); break;16. }17. }What is the result?A. threeB. otherC. An exception is thrown at runtime.D. Compilation fails because of an error on line 12.E. Compilation fails because of an error on line 13.F. Compilation fails because of an error on line 15. Answer: A 就是两个Integer类型相加Question 6Given:11. public static void main(String[] args) {12. String str = "null";13. if (str == null) {14. System.out.println("null");15. } else (str.length() == 0) {16. System.out.println("zero");17. } else {18. System.out.println("some");19. }20. }‘What is the resul t?A. nullB. zeroC. someD. Compilation fails.E. An exception is thrown at runtime. Answer: D 这题真恶心 15行少个ifQuestion 7Given:10.int x=0;11.int y=10;12. do {l3. y--;14. ++x;15. } while (x < 5);16. System.out.print(x + "," + y);What is the result?A. 5,6B. 5,5C. 6,5D. 6,6Answer: B (91,82,73,64,55)没啥争议Question 8Given:25.int x=12;26. while (x < 10) {27. x--;28. }29. System.out.print(x);What is the result?A. 0B. 10C. 12D. Line 29 will never be reached.Answer: C 12>10,所以直接跳出循环,输出x=12 Question 9Given:35. int x= 10;36. do {37. x--;38. } while(x< 10);How many times will line 37 be executed?A. ten timesB. zero timesC. one to me timesD. more than ten timesAnswer: D 死循环Question 10Given:11. public static void main(String[] args) {12. for (int i=0;i<= 10;i++){13. if( i>6) break;14. }15. System.out.println(i);16. }What is the result?A. 6B. 7C. 10D. 11E. Compilation fails.F. An exception is thrown at runtime.Answer: E 15行i超出了作用域Question 11Given:55. int []x= {1, 2,3,4, 5};56. int y[] =x;57. System.out.println(y[2]);Which is true?A. Line 57 will print the value 2.B. Line 57 will print the value 3.C. Compilation will fail because of an error in line 55.D. Compilation will fail because of an error in line 56. Answer: B 没争议,考察数组下标是从0开始Question 12Which two code fragments(片段)correctly(正确) create and initialize a static array of int elements? (Choose two.)A. static final int[] a = { 100,200 };B. static final int[] a;static { a=new int[2]; a[0]=100; a[1]=200; }C. static final int[] a = new int[2] { 100,200 };D. static final int[] a;static void init() { a = new int[3]; a[0]=100; a[1]=200; } Answer: AB c不能指定长度,d不能在init方法中赋值,要么在static代码块中Question 13Given:11. public static void main(String[] args) {12. Object obj = new int[] { 1,2,3 };13. int[] someArray = (int[])obj;14. for (int i: someArray) System.out.print(i +" ")15. }‘What is the result?A. 1 2 3B. Compilation fails because of an error in line 12.C. Compilation fails because of an error in line 13.D. Compilation fails because of an error in line 14.E. A ClassCastException is thrown at runtime.Answer: A 没争议,foeach循环遍历数组Question 14Given:11. String[] elements = { "for", "tea", "too" };12. String first = (elements.length > 0)? elements[0] : null;What is the result?A. Compilation fails.B. An exception is thrown at runtime.C. The variable first is set to null.D. The variable first is set to elements[0].Answer: DQuestion 15Given:10. public class Bar {11.static void foo(int...x) {12. // insert code here13. }14. }Which two code fragments, inserted independently (独立的) at line 12, will allow the class to compile? (Choose two.)A. foreach(x) System.out.println(z);B. for(int z : x) System.out.println(z);C. while( x.hasNext()) System.out.println( x.next());D. for( int i=0; i< x.length; i++ ) System.out.println(x[i]);Answer: BD x相当于一个数组,a明显错没有foreach,c中x没有hadNext方法Question 16A programmer(程序员)needs to create a logging method that can accept(接受) an arbitrary(随意任意) number of arguments. For example, it may be called in theseways:logIt("log message 1 ");logIt("log message2”,”log message3");logIt("log message4", "log message5", "log message6");Which declaration(说明)satisfies(符合)this requirement(需求)?A. public void logIt(String * msgs)B. public void logIt(String [] msgs)C. public void logIt(String... msgs)D. public void logIt(String msg1, String msg2, String msg3)Answer: C 可变长参数Question 171. public class A {2. public String doit(int x, int y) {3. return "a";4. }5.6. public String doit(int... vals) {7. return "b";8. }9. }Given:25. A a=new A();26. System.out.println(a.doit(4, 5));What is the result?A. Line 26 prints "a" to System.out.B. Line 26 prints "b" to System.out.C. An exception is thrown at line 26 at runtime.D. Compilation of class A will fail due to an error in line 6.Answer: A 确定参数和可变长参数同时存在的时候,优先考虑确定参数的Question 18Given a file GrizzlyBear.java:1. package animals.mammals;2.3. public class GrizzlyBear extends Bear {4. void hunt() {5. Salmon s = findSalmon();6. s.consume();7. }8. }and another file, Salmon.java:1. package animals.fish;2.3. public class Salmon extends Fish {4. void consume() { /* do stuff */ }5. }Assume(假定) both classes are defined in the correct directories for theft packages, and that the Mammal class correctly defines the findSalmon() method. Which two changes allow this code to compile correctly? (Choose two.)A. add public to the start of line 4 in Salmon.javaB. add public to the start of line 4 in GrizzlyBear.javaC. add import animals.mammals.*; at line 2 in Salmon.javaD. add import animals.fish.*; at line 2 in GrizzlyBear.javaE. add import animals.fish.Salmon.*; at line 2 in GrizzlyBear.javaF. add import animals.mammals.GrizzlyBear.*;at line 2 in Salmon.javaAnswer: AD 调用不同包下的类,要先导入,方法权限要设置成publicQuestion 19Given:10. package com.sun.scjp;11. public class Geodetics {12. public static final double DIAMETER = 12756.32; // kilometers13. }Which two correctly access(访问) the DIAMETER member of the Geodetics class? (Choose two.)A. import com.sun.scjp.Geodetics;public class TerraCarta {public double halfway(){ return Geodetics.DIAMETER/2.0; } }B. import static com.sun.scjp.Geodetics;public class TerraCarta {public double halfway() { return DIAMETER/2.0; } } C. import static com.sun.scjp.Geodetics. *;public class TerraCarta {public double halfway() { return DIAMETER/2.0; } } D. package com.sun.scjp;public class TerraCarta {public double halfway() { return DIAMETER/2.0; } } Answer: AC b中不能静态导入类,c中静态导入类属性,正确,d访问错误很明显Question 20Given classes defined in two different files:1. package util;2. public class BitUtils {3. private static void process(byte[] b) { }4. }1. package app;2. public class SomeApp {3. public static void main(String[] args) {4. byte[] bytes = new byte[256];5. // insert code here6. }7. }What is required(必需的)at line 5 in class SomeApp to use the process methodof BitUtils?A. process(bytes);B. BitUtils.process(bytes);C. app.BitUtils.process(bytes);D. util.BitUtils.process(bytes);E. import util.BitUtils. *; process(bytes);F. SomeApp cannot use the process method in BitUtils.Answer: F 私有的,不能被访问Question 21Given a class Repetition(重复):1. package utils;2.3. public class Repetition {4. public static String twice(String s) { return s + s; }5. }and given another class Demo:1. // insert code here2.3. public class Demo {4. public static void main(String[] args) {5. System.out.println(twice("pizza"));6. }7. }Which code should be inserted at line 1 of Demo.java to compile and run Demo to print “pizzapizza”?A. import utils.*;B. static import utils.*;C. import utils.Repetition.*;D. static import utils.Repetition. *;E. import utils.Repetition.twice();F. import static utils.Repetition.twice;G. static import utils.Repetition.twice;Answer: F 静态导入Question 22Given:1. package test;2.3. class Target(目标) {4. public String name = "hello";5. }What can directly(直接的)access and change the value of the variable(变量) name?A. any classB. only the Target classC. any class in the test packageD. any class that extends TargetAnswer: C default类型的类本包访问权限Question 23Given:11. rbo = new ReallyBigObject();12. // more code here13. rbo = null;14. /* insert code here */Which statement(语句) should be placed at line 14 to suggest(促成)that the virtual machine(虚拟机)expend(消耗)effort(努力)toward recycling(回收) the memory used by the object rbo?A. System.gc();B. Runtime.gc();C. System.freeMemory();D. Runtime.getRuntime().growHeap();E. Runtime.getRuntime().freeMemory();Answer: A 题很简单。

4、机器人等级考试三级三级理论试卷四

4、机器人等级考试三级三级理论试卷四

全国青少年机器人技术等级考试三级(编程)模拟试题四一、单选题(共30 题,每题2 分)1.使用(A)传感器时,通常使用模块A、声音传感器B、触感传感器C、巡线传感器D、避障传感器2.从以下程序中可以看出b是(A)A、负数B、正数C、0D、负的小数3.程序中的模块,在代码中应表示为(B)A、“=”B、“==”C、“!=”D、“≠”4.根据欧姆定律,下列说法正确的是(C)A、同一导体的电阻与加在它两端的电流成反比B、同一导体的电阻与通过它两端的电压成正比C、同一导体两端的电压增大几倍,通过他的电流也增大几倍D、导体两端电压为0时,导体的电阻也为05.光敏电阻如何连接时光线越强,模拟输入信号返回值越小(B)A、B、C、D、另外三个接法均错误6.下列电路基本组成,说法不正确的是(C)A、电路中不可缺少的组成部分有电源、开关、导线、用电器B、电路中电源是用来提供电能的C、电路中用电器可以提供电能D、用电器会将电能转化为其他能量7.中国家庭常用电压为(C)A、55VB、110VC、220VD、330V8.与门电路输入0和1会输出(A)A、0B、1C、先输出0后输出1D、先输出1后输出09.下列流程图中表示if-else语句的是(C)A、B、C、D、10.如下图所示,一个串联电路串联了5个灯泡,测得电源旁边的电流为10A,则通过每个灯泡的电流为(B)A、1AB、10AC、2AD、100A11.电压的单位用(C)符号表示A、EB、UC、VD、Ω12.如图所示电路,分析灯L1灯L2和电压表的连接方式,正确的是(C)A、L1、L2、电压表都是并联B、L1、L2、电压表都是串联C、L1与L2串联,L1与电压表并联D、L1与L2并联,L1与电压表串联13.对此模块描述正确的是(A)A、此模块一共循环5次B、此模块一共循环4次C、此模块一共循环6次D、以上说法都不对14.下列欧姆定律的公式正确的是(B)A、U=I/RB、U=I*RC、R=U*ID、I=R/U15.两节普通干电池并联后电压为(A)A、1.5VB、3VC、6VD、36V16.下列属于整型数据的是(A)A、123B、abcC、11.2D、6.23617.针对此模块,下列说法不正确的是(C)A.此模块为分支结构B.此模块的代码形式为C.此模块为循环结构D.此模块可以对两种对立的情况执行不同的操作18.下列的那个选项不属于程序的三种基本结构(D)A、循环结构B、分支结构C、顺序结构D、总线结构19.如下图所示并联电路中三个小灯泡的电阻值比例为R1:R2:R3=1:2:4,那么下列关于电压电流的说法正确的是(C)A.三个小灯泡两端的电压值比例U1:U2:U3=1:2:4B.通过三个小灯泡的电流比例I1:I2:I3=1:2:4C.通过三个小灯泡的电流比例I1:I2:I3=4:2:1D.通过三个小灯泡的电流大小相同20.下列说法错误的是(D)A.电源是提供电压的装置B.电压是形成电流的原因C.电流是电荷的定向移动形成的D.电路两端只要有电压就一定有电流21.下列语句是条件语句的是(A)A. B.C. D.22.下列关于电流方向说法正确的是(C)A.电流方向和电子运动的方向相同B.电流方向是负电荷移动的方向C.在电路中电流方向是从正极出发,通过用电器回到负极D.在金属导线中,电流方向与自由移动的电荷运动方向相同23. 下列不是电流产生必要条件的是(D)A、电路中必须有闭合回路形成通路B、必须具有能够自由移动的电荷C、导体两端存在电压差D、必须具有能够自由移动的正电荷24.如下图所示,两端电压保持不变,电阻大小为5Ω,此时通过电阻的电流大小为1A,当我们将电阻更换阻值为2.5Ω,这时通过电阻的电流为(B)A、1AB、2AC、4AD、不确定25.程序中高电平一般用(B)表示A、0B、1C、0或1D、以上选项都不对26.此模块可以实现(A)A、在V0口的小灯点亮B、调节V0口的小灯亮度C、在A0口的小灯点亮D、调节A0口的小灯亮度27.对于导体说法正确的是(B)A、同种材料,相同长度的导体,横截面积越大电阻值越大B、同种材料,相同横截面积的导体,长度越长电阻值越大C、不同材质的导体,只要导体长度,横截面积相同,电阻值也相同D、导体容易导电是因为导体内部一定有可以自由移动的正电荷28.在1陶瓷,2铜,3盐水,4塑料,5玻璃,6水银,六种物质中,通常情况下属于导体的是(D)A、145B、156C、234D、23629.运算符逻辑与的符号为(D)A、&B、||C、!D、&&30.如下图所示,当按键按下时,对A1引脚描述正确的是(A)A、应使用数字输入模块,并且A1返回高电平B、应使用模拟输入模块,并且A1返回高电平C、应使用模拟输入模块,并且A1返回低电平D、应使用数字输入模块,并且A1返回低电平二、多选题(共5题,每题4 分)1.C语言的特点(ABCD)A、语言简洁紧凑使用方便灵活B、运算符、数据类型丰富C、具有结构化的控制语句D、语法限制不太严格,程序设计自由度大2、下列关于串联电路说法正确的是(ACD)A、串联电路只有一个回路B、串联电路中每个用电器通过的电流和电阻成反比C、串联电路中每个用电器两端的电压和电阻成正比D、串联电路中电流处处相等3、对此模块描述正确的是(ACD)A、可以设定管脚模式B、内部程序可以循环执行C、内部程序执行一次D、可以设置串行通信波特率4、如图所示电路中电流表测量的是(ACD)A、A1测量的是通过灯L1的电流B、A2测量的是通过灯L2的电流C、A2测量的是灯L1和灯L2的电流之和D、A2测量的是干路的电流5、对于这个模块下列说法正确的是(AB)A、属于逻辑符号模块B、此模块可以实现两边条件只要有一个成立,则整体为“真”C、此模块的作用是可以实现两边条件要全部成立,则整体为“真”D、此模块为逻辑非模块三、判断题(共10题,每题2 分)1、一个C语言程序可以没有主函数(×)2、算法就是为解决一个问题而采取的方法和步骤(√)3、在时间和数值上都不连续的物理量称为模拟量(×)4、该循环模块可循环11次(×)5、用电器正常工作的电路中电流可以无限大(×)6、模块代表的是两边表达式要同时成立,整个表达式才算成立(×)7、正常工作的二极管智能单向导电(√)8、该模块可以点亮外接的LED灯(√)9、在程序中,//后面的部分可以被执行(×)10、并联电路中,各支路电流与电阻成反比(√)。

理论综合试卷(三级)答案-20200727151131107

理论综合试卷(三级)答案-20200727151131107

青少年机器人技术等级考试理论综合试卷(三级)分数:100.00 题数:30一、单选题(共20题,共80分)1. Arduino UNO主控板数字信号引脚的工作模式,下列说法正确的是?A、有数字信号输入模式、数字信号输出模式两种B、有数字信号输入模式、数字信号输出模式、内部下拉数字信号输入模式三种C、有数字信号输入模式、数字信号输出模式、内部上拉数字信号输入模式三种D、有高电平模式、低电平模式两种试题编号:20200604154028957题型:单选题答案:C难度:一般试题解析:书中第54页解析2.执行如下语句,串口监视器的显示值是?A、0B、1C、255D、256试题编号:20200604154028690题型:单选题答案:A难度:一般试题解析:字节数据类型范围为1/0 255为1 256为03. 在我们的日常生活中接触过许多家用电器,比如电灯、电冰箱、洗衣机、电脑等,家用电器之间的连接方法是?A、都是串联B、都是并联C、可以串联,也可以是并联D、多盏电灯应该是串联,电脑与电冰箱等应该并联试题编号:20200604154028596题型:单选题答案:B难度:试题解析:4.执行下列语句,3秒后,2、3引脚的状态?A、高、低B、低、高C、高、高D、低、低试题编号:20200604154028894题型:单选题答案:B难度:一般试题解析:初始化程序只执行一次5.读取电路中按键的返回值时,使用下列哪个模块? A、B、C、D、试题编号:20200604154028847题型:单选题答案:A难度:一般试题解析:6. 对此模块描述正确的是?A、此模块一共循环1次B、此模块一共循环4次C、此模块一共循环5次D、此模块一共循环6次试题编号:20200604154028738题型:单选题答案:C难度:试题解析:1 3 5 7 97.下列流程图中,没有选择结构语句的是?A、B、C、D、试题编号:20200604154028721题型:单选题答案:A难度:一般试题解析:8.下列电路中,属于串联电路的有? A、B、C、D、试题编号:20200604154028941题型:单选题答案:C难度:一般试题解析:9. 电压过高会对人体造成伤害,经验表明人体安全电压不得高于?A、220VB、36VC、12VD、5V试题编号:20200604154028565题型:单选题答案:B难度:试题解析:10. 在常温情况下,下列物体属于绝缘体的是?A、石墨B、普通橡胶C、水银D、潮湿的木头试题编号:20200604154028612题型:单选题答案:B难度:试题解析:11. 利用光敏电阻传感器向Arduino模拟输入A3口发送信息,下列值可能是返回值的是?A、-128B、256C、-52D、1024试题编号:20200604154028910题型:单选题答案:B难度:试题解析:模拟输入的范围是0~102312.下图是一个按键控制LED灯的电路连接图,和对应的程序。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

QUESTION 121Given:Which code, inserted at line 15, creates an instance of the Point class defined in Line?A. Point p = new Point();B. Line.Point p = new Line.point();C. The Point class cannot be instatiated at line 15.D. Line 1 = new Line() ; 1.Point p = new 1.Point();Answer: ( B )静态内部类创建方法非静态内部类的构造:Line.Point p = new Line().new Point();参考大纲:面向对象—内部静态类QUESTION 122Given:Which statement is true?A. The code will compile without changes.B. The code will compile if public Tree() { Plant(); } is added to the Tree class.C. The code will compile if public Plant() { Tree(); } is added to the Plant class.D. The code will compile if public Plant() { this("fern"); } is added to the Plant class.E. The code will compile if public Plant() { Plant("fern"); } is added to the Plant class.Answer: ( D )子类默认调用父类无参构造函数,而Plant没有无参构造函数,因此须显示调用有参构造函数参考大纲:面向对象QUESTION 123Given:Which two code fragments, inserted independently at line 12, will allow the class to compile? (Choose two.)A. foreach( x ) System.out.print1n(z);B. for( int z : x ) System.out.print1n(z);C. while( x.hashNext() ) System.out.print1n( x.next() )D. for( int i=0; i < x.length; i++ ) System.out.println(x[i]);Answer: ( B, D )可变参数方法编译后变成数组参数方法,然后利用循环结构取出数组的值参考大纲:流程控制和可变长度参数QUESTION 124Exhibit:Which statement is true about the classes and interfaces in the exhibit?A. Compilation will succeed for all classes and interfaces.B. Compilation of class C will fail because of an error in line 2.C. Compilation of class C will fail because of an error in line 6.D. Compilation of class AImpl will fail because of an error in line 2.Answer: ( C )参考大纲:面向对象—复写QUESTION 125Place the lines in the correct order to complete the enum。

enum Element {Answer: ( )enum Element {EARTH, WIND,FIRE{public String info(){return “Hot”;}};public String info(){return “element”;}}列举的内容之后要加上“;”参考大纲:面向对象—enumQUESTION 126Place the code elements in order so that the resulting Java source file will compile correctly, resulting in a class called com.sun.cert.AddressBook.Answer: ( )package com.sum.cert;import java.util.*;public class AddressBook{ArrayList entries;}参考大纲:面向对象—语法基础QUESTION 127Which two classes correctly implement both the ng.Runnable and the ng.Clonable interfaces? (Choose two.)A. public class Session implements Runnable, Clonable {public void run ();public Object clone();}B. public class Session extends Runnable, Clonable {public void run() {/*do something*/}public Object clone() {/*make a copy*/}}C. public class Session implements Runnable, Clonable {public void run() {/*do something*/}public Object clone() {/*make a copy*/}}D. public abstract class Session implements Runnable, Clonable {public void run() {/*do something*/}public Object clone() {/*make a copy*/}}E. public class Session implements Runnable, implements Clonable {public void run() {/*do something*/}public Object clone() {/*make a copy*/}}Answer: ( C, D )A 错误Session是具体类,方法必须实现B 实现interface用implementsC 正确D 正确E 错误implements只能出现一次参考大纲:多线程QUESTION 128Given:Which statement is true?A. 420 is the outputB. An exception is thrown at runtime.C. All constructors must be declared public.D. Constructors CANNOT use the private modifier.E. Constructors CANNOT use the protected modifier.Answer: ( A )参考大纲:面向对象QUESTION 129Given:What is the result?A. foofoofoofoofooB. foobarfoobarbarC. foobarfoofoofooD. foobarfoobarfooE. barbarbarbarbarF. foofoofoobarbarG. foofoofoobarfooAnswer: ( D )参考大纲:面向对象—属性的重载和遮蔽,该题中子类遮蔽了父类的属性QUESTION 130Which two statements are true about has-a and is-a relationships? (Choose two.)A. Inheritance represents an is-a relationship.B. Inheritance represents an has-a relationship.C. Interfaces must be use when creating a has-a relationship.D. Instance variables can be used when creating a has-a relationship.Answer: ( A, D )参考大纲:面向对象QUESTION 131 --------Given:Which statement is true about the class of an object that can reference the variable base?A. It can be any class.B. No class has access to base.C. The class must belong to the geometry package.D. The class must be a subclass of the class Hypotenuse.Answer: ( C )参考大纲:面向对象QUESTION 132Given:Place the names "A" and "B" in the following output.Answer: ( )参考大纲:面向对象class B has name AQUESTION 133Given:What is the result?A. Compilation fails because of an error in line 3.B. Compilation fails because of an error in line 7.C. Compilation fails because of an error in line 9.D. If you define D e = new E(), then e.bMethod() invokes the version of bMethod()defined in line 5.E. If you define D e = (D)(new E()), then e.bMethod() invokes the version of bMethod()defined in line 5.F. If you define D e = (D)(new E()), then e.bMethod() invokes the version of bMethod()defined in line 9.Answer: ( F ) E类的对象调用b.Method(),因为E类体里有这个方法就遮蔽了父类的方法参考大纲:面向对象QUESTION 134Which two statements are true? (Choose two.)A. An encapsulation, public class promotes re-use.B. Classes that share the same interface are always tightly encapsulated.C. An encapsulated class allows subclasses to overload methods, but does NOT allowoverriding methods.D. An encapsulated class allows programmer to change an implementation withoutaffecting outside code.Answer: ( A, D)参考大纲:面向对象QUESTION 135 -----BTPlace the Relations on their corresponding Implementation Structures.Note: Not all Implementation Structres will be used.Answer: ( )参考大纲:面向对象QUESTION 136Given:And:What is the result?A. HelloB. Hello WorldC. Compilation fails.D. Hello World 5E. The code runs with no output.F. An exception is thrown at runtime.Answer: ( C )19行应改为this(),应该放在第一行;参考大纲:面向对象QUESTION 137 --Given:Which two, independently, will allow Sub to compile? (Choose two.)A.Change line 2 to: public int a;B. Change line 2 to: protected int a;C. Change line 13 to: public Sub() {this(5);}D. Change line 13 to: public Sub() {super(5);}E. Change line 13 to: public Sub() {super(a);}Answer: ( C, D )参考大纲:面向对象QUESTION 138 --Given:What is the result when the programmer attempts to compile the code and run it with the command:java Converter 12 ?A. It is true that j == i.B. It is false that j == i.C. An exception is thrown at runtime.D. Compilation fails because of an error in line 13.Answer: ( D )参考大纲:语言基础QUESTION 139Given:What is the output?A. 42B. 420C. 462D. 42042E. Compilation failsF. An exception is thrown at runtime.Answer: ( D )参考大纲:语言基础QUESTION 140 -- BTAssuming that the serializeBanana2() and the deserializeBanana2() methods willcorrectly use Java serialization and given:What is the result?A. Compilation failsB. 1 restored 42C. 12 restored 42D. 121 restored 42E. 1212 restored 42F. An exception is thrown at runtimeAnswer: ( D )因为父类Food未实现serializable接口,反序列化时将调用Food的构造函数.见工程执行结果参考大纲:IO操作—序列化机制QUESTION 141Given:What is the result?A. a b cB. 1 2 3C. a1b2c3D. a1 b2 c3E. Compilation failsF. The code runs with no output.G. An exception is thrown at runtime.Answer: ( A )参考大纲:实用APIQUESTION 142Given:What is the result?A. Compilation failsB. After line 15, the value of age is 5.C. After line 15, the value of age is 3.D. An exception is thrown at runtime.Answer: ( D )抛出java.util.InputMismatchException异常正确读取方法:scaner.next();scaner.nextInt();scaner.nextBoolean();scaner.nextInt();参考大纲:实用API —Scanner简易I/O工具QUESTION 143Given a valid DateFormat object named df, andWhat updates d's value with the date represented by ds?A. AB. BC. CD. DAnswer: ( C )DateFormat类的parse(String s) 会抛ParseException异常.参考大纲:实用API —DataFormatQUESTION 144Place the Fragments into the program, so that the program will get lines from a text file, display them, and then close all the resources.Answer: ( )参考大纲:IO操作QUESTION 145Given:And:Which changes can you make to Target without affecting Client?A. Line 4 of class Target can be changed to return i++;B. Line 2 of class Target can be changed to private int i =1;C. Line 3 of class Target can be changed to private int addOne(){D. Line 2 of class Target can be changed to private Integer i = 0;Answer: ( D )A: return ++i; 和return i++; 不一样.参考大纲:实用APIQUESTION 146Given:Which statement is true?A. Compilation will succeed if A extendsB.B. Compilation will succeed if B extends A.C. Compilation will always fail because of an error in line7.D. Compilation will always fail because of an error in line8.Answer: ( B )参考大纲:面向对象—重写QUESTION 147Given:What is the result?A. Compilation fails.B. Cannot add ToppingsC. The code runs with no output.D. A NullPointerException is thrown in Line 4.Answer: ( A )final方法不能重写参考大纲:面向对象QUESTION 148Insert six modifiers into the code such that it meets all of these requirements:Answer: ( )2,4,8,9行符合条件一; 3行符合条件二; 5行符合条件三.参考大纲:语言基础—存取权限QUESTION 149Given:And:What is the result?A. The code runs with no output.B. An exception is thrown at runtime.C. Compilation fails because of an error in line 20.D. Compilation fails because of an error in line 21.E. Compilation fails because of an error in line 23.F. Compilation fails because of an error in line 25.Answer: ( F )a 对象没有y( )方法参考大纲:面向对象QUESTION 150A programmer needs to create a logging method that can accept an arbitrary number of arguments. For example, it may be called in these ways:Which declaration satisfies this requirement?A. public void logIt(String * msgs)B. public void logIt(String [] msgs)C. public void logIt(String... msgs)D. public void logIt(String msg1, String msg2, String msg3)Answer: ( C )参考大纲:面向对象可变参数QUESTION 151----------------------------------Exhibit:What is the result?A. 4321B. 0000C. An exception is thrown at runtime.D. Compilation fails because of an error in line 18.Answer: ( D )父类没有无参构造函数参考大纲:面向对象QUESTION 152Given:Which code inserted at line 14 causes the foo method to print RED, GREEN, and BLUE?A. for( Color c : Color.values() )B. for( Color c= RED; c<=BLUE; c++)C. for( Color c ; c.hasNext() ; c.next() }D. for( Color c : Color[0]; c <=Color[2]; c++)E. for( Color c : Color[0]; c <=Color.BLUE; c++)Answer: ( A )enum Color extends Enum{ };Enum类的子类有values(),可以返回子类的数组.参考大纲:面向对象—enumQUESTION 153Exhibit:Given this code from Class B:What is the result?A. Compilation of class A fails.B. Line 28 prints the value 3 to System.out.C. Line 28 prints the value 1 to System.out.D. A runtime error occurs when line 25 executes.E. Compilation fails because of an error in line 28.Answer: ( A )第6行错误参考大纲:面向对象QUESTION 154Given:Which three methods, inserted individually at line 14, will correctly complete class Two? ( Choose three.)A. int foo() {/*more code here*/}B. void foo() {/*more code here*/}C. public void foo() {/*more code here*/}D. private void foo() {/*more code here*/}E. protected void foo() {/*more code here*/}Answer: ( B, C, E )参考大纲:面向对象QUESTION 155Given:A programmer wants to create an interface calledB that has A as its parent.Which interface declaration is correct?A. public interface B extends A {}B. public interface B implements A {}C. public interface B instanceOf A {}D. public interface B inheritsFrom A {}Answer: ( A )参考大纲:面向对象QUESTION 156Given:And a class Circle that extends and fully implements the Shape class. Which is correct?A. Shape s = new Shape();s.setAnchor(10,10);s.draw();B. Circle c = new Shape();c.setAncohor(10,10);c.draw();C. Shape s =new Circle();s.setAnchor(10,10);s.draw();D. Shape s =new Circle();s->setAncohor(10,10);s->draw();E. Shape s =new Circle();s.Shape.setAnchor(10,10);s.shape.draw();Answer: ( C )参考大纲:面向对象QUESTION 157Given:Which class correctly uses the Data interface and Info class?A. public class Employee extends Info implements Data {public void load() {/*do something*/}}B. public class Employee implements Info extends Data {public void load() {/*do something*/}}C. public class Employee extends Info implements Data {public void load() {/*do something*/}public void Info.load(){/*do something*/}}D. public class Employee implements Info extends Data {public void Data.load() {/*do something*/}public void load(){/*do something*/}}E. public class Employee implements Info extends Data {public void load() {/*do something*/}public void Info.load(){/*do something*/}}F. public class Employee extends Info implements Data {public void Data.load() {/*do something*/}public void Info.load(){/*do something*/}}Answer: ( A )参考大纲:面向对象QUESTION 158Which two code fragments correctly create and initialize a static array of int elements? (Choose two.)A. static final int[] a = { 100,200 };B. static final int [] a;static { a=new int[2]; a[0]=100; a[1]=200; }C. static final int [] a = new int[2]{ 100,200 }; ------------------------------------2D. static final int [] a;static void init() { a=new int[3]; a[0]= 100; a [1]=200; }Answer: ( A, B )参考大纲:语言基础—数组QUESTION 159A UNIX user named Bob wants to replace his chess program with a new one, but he is not sure where the old one is installed. Bob is currently able to run a Java chess program starting from his home directory /home/bob using the command:java -classpath /test games.ChessBob's CLASSPATH is set (at login time) to:/usr/lib:/home/bob/classes:/opt/java/lib:What is a possible location for the Chess.class file?A. /test/Chess.classB. /home/bob/Chess.classC. /test/games/Chess.classD. /usr/lib/games/Chess.classE. /home/bob/games/Chess.classF. Inside jarfile /opt/java/lib/Games.jar (with a correct manifest)G. Inside jarfile /home/bob/downloads/Games.jar (with a correct manifest)Answer: ( C )参考大纲:语言基础QUESTION 160Given:What is the result?A. s 14B. s 16C. s 10D. Compilation failsE. An exception is thrown at runtime.Answer: ( D )第19行错误,接口中定义的方法都是抽象公共的,变量都是常量。

相关文档
最新文档