ImageVerifierCode 换一换
格式:DOC , 页数:25 ,大小:127KB ,
资源ID:1336861      下载积分:5000 积分
快捷下载
登录下载
邮箱/手机:
温馨提示:
如需开发票,请勿充值!快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝扫码支付 微信扫码支付   
注意:如需开发票,请勿充值!
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【http://www.mydoc123.com/d-1336861.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(【计算机类职业资格】计算机Java认证-理解方法和变量的作用域、数组编程及答案解析.doc)为本站会员(王申宇)主动上传,麦多课文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知麦多课文库(发送邮件至master@mydoc123.com或直接QQ联系客服),我们立即给予删除!

【计算机类职业资格】计算机Java认证-理解方法和变量的作用域、数组编程及答案解析.doc

1、计算机 Java认证-理解方法和变量的作用域、数组编程及答案解析(总分:100.00,做题时间:90 分钟)一、B不定项选择题/B(总题数:30,分数:100.00)1.A method needs to be created that accepts an array of floats as an argument and does not return any variables. The method should be called setPoints. Which of the following method declarations is correct? A. setPoin

2、ts(float points) . B. void setPoints(float points) . C. void setPoints(float points) . D. float setPoints(float points) .(分数:3.00)A.B.C.D.2.When the void keyword is used, which of the following statements are true? (Choose all that apply.) A. A return statement with a value following it must be used

3、. B. A return statement with a value following it can optionally be used. C. A return statement with a value following it should never be used. D. A return statement by itself must be used. E. A return statement by itself can optionally be used. F. A return statement by itself should never be used.

4、G. A return statement must be omitted. H. A return statement can optionally be omitted. I. A return statement should never be omitted.(分数:3.00)A.B.C.D.E.F.G.H.I.3.Given the SampleClass, what is the output of this code segment?SampleClass s = new SampleClass();s.sampleMethod(4.4, 4);public class Samp

5、leClass public void sampleMethod(int a, double b) System.out.println(“Method 1“);public void sampleMethod(double b, int a) System.out.println(“Method 2“); A. Method 1 B. Method 2 C. Method 1 Method 2 D. Method 2 Method 1 E. Compiler error(分数:3.00)A.B.C.D.E.4.Given the class FloatNumber and method ad

6、dHalf, what is the output if the following code segment is executed?public class FloatNumber float number;public FloatNumber(float number this.number = number;floatgetNumber( retum number;void setNumber(float number) this.number = number;void addHalf(FloatNumber value) value.setNumber(value.getNumbe

7、r()+(value.getNumber()/2f);/* CODE SEGMENT */FloatNumber value = new FloatNumber(1f);addHalf(value);System.out.println(“value =“+value.getNumber(); A. value = 1 B. value = 1.5 C. value = 2 D. value = 0(分数:3.00)A.B.C.D.5.Objects are passed by _. A. Value B. Sum C. Reference D. Pointer(分数:3.00)A.B.C.D

8、.6.Primitives are passed by _. A. Value B. Sum C. Reference D. Pointer(分数:3.00)A.B.C.D.7.You need to create a class to store information about books contained in a library. What variable scope is best suited for the variable that will store the title of a book? A. Local variable B. Static variable C

9、. Global variable D. Method parameter E. Instance variable(分数:3.00)A.B.C.D.E.8.Given the SampleClass, when the following code segment is executed, what is the value of the instance variable size?SampleClass sampleClass = new SampleClass(5);public class SampleClass private int size;public SampleClass

10、(int size) size = size; A. 0 B. 1 C. 5 D. Compiler error E. Runtime error(分数:3.00)A.B.C.D.E.9.Given the SampleClass, what is the output of this code segment?SampleClass sampleClass = new SampleClass();public class SampleClass private int size;private int priority;public SampleClass() super();System.

11、out.println(“Using default values“);public SampleClass(int size) this.size = size;System.out.println(“Setting size“);public SampleClass(int priority) this.priority = priority;System.out.println(“Setting priority“); A. Using default values B. Setting size C. Setting priority D. Compiler error(分数:3.00

12、)A.B.C.D.10.What constructor is equivalent to the one listed here?public SampleConstructor( System.out.println(“SampleConstructor“); A. public SampleConstructor() this(); System.out.println(“Sample Constructor“); B. public SampleConstructor() super(); System.out.println(“Sample Constructor“); C. pub

13、lic SampleConstructor() this.SampleConstructor(); System.out.println(“Sample Constructor“); D. public SampleConstructor() super.SampleConstructor(); System.out.println(“Sample Constructor“); E. None of the above(分数:3.00)A.B.C.D.E.11.Given the SampleClass, what is the output of this code segment?Samp

14、leClass sampleClass = new SampleClass();public class SampleClass private int size;public SampleClass() this(1);System.out.println(“Using default values“);public SampleClass(int size) this.size = size;System.out.println(“Setting size“); A. Using default values B. Setting size C. Using default values

15、Setting size D. Setting size Using default values E. Compiler error(分数:3.00)A.B.C.D.E.12.What is the effect of the following line of code?super() A. The method that is overridden by the current method is called. B. The parent classs constructor is called. C. The current classs constructor is called.

16、 D. The child classs constructor is called E. The current method is recursively called.(分数:3.00)A.B.C.D.E.13.Given the SampleClass, what is the output of this code segment?SampleClass s = new SampleClass();SampleClass.sampleMethodOne();public class SampleClass public static void sampleMethodOne() sa

17、mpleMethodTwo();System.out.println(“sampleMethodOne“);public void sampleMethodTwo() System.out.println(“sampleMethodTwo“); A. sampleMethodOne B. sampleMethodTwo C. sampleMethodOne sampleMethodTwo D. sampleMethodTwo sampleMethodOne E. Compiler error(分数:3.00)A.B.C.D.E.14.Given the SampleClass, what is

18、 the value of currentCount for the instance of object x after the code segment had be executed?SampleClass x = new SampleClass();SampleClass y = new SampleClass();x.increaseCount();public class SampleClass private static int currentCount=();public SampleClass() currentCount+;public void increaseCoun

19、t() currentCount+; A. 0 B. 1 C. 2 D. 3 E. Compiler error F. Runtime error(分数:3.00)A.B.C.D.E.F.15.Static methods have access to which of the following? (Choose all that apply.) A. Static variables B. Instance variables C. Standard methods D. Static Methods E. None of the above(分数:3.00)A.B.C.D.E.16.Wh

20、at lines will compile without errors? (Choose all that apply.) A. Object obj = new Object(); B. Object obj = new Object(); C. Object obj = new Object(); D. Object obj = new Object; E. Object obj = new Object3(); F. Object obj = new Object7; G. Object obj = new Object; H. Object obj = new Object3();

21、I. Object obj = new Object7; J. Object8 obj = new Object; K. Object3 obj = new Object3(); L. Object7 obj = new Object7; M. Object obj = new new Object(), new Object(); N. Object obj = new Object(), new Object(); O. Object obj = new Object1, new Object2;(分数:3.00)A.B.C.D.E.F.G.H.I.J.K.L.M.N.O.17.What

22、is the output of the following code segment?String numbers = “One“, “Two“, “Three“;System.out.println(numbers3+“ “+numbers2+“ “+numbers1); A. One Two Three B. Three Two One C. A compile time error will be generated. D. A runtime exception will be thrown.(分数:3.00)A.B.C.D.18.What is the output of the

23、following code segment?String numbers = “One“ “Two“, “Three“;for(String s : numbers)System.out.print(s+“ “); A. One Two Three B. Three Two One C. A compile time error will be generated. D. A runtime exception will be thrown.(分数:3.00)A.B.C.D.19.What is the output of the following code segment?int tes

24、tScores = 80,63,99,87,100;System.out.println(“Length: “ + testScores.length); A. Length: 4 B. Length: 5 C. Length: 100 D. A compile time error will be generated. E. A runtime exception will be thrown.(分数:3.00)A.B.C.D.E.20.What is the output of the following code segment? Integer integerArray1 = new

25、Integer(100), new Integer(1), new Integer(30), new Integer (50); Integer integerArray2 = new Integer2; integerArray20 = new Integer(100); System.arraycopy(integerArray1, 2, integerArray2, 1, 1); for(Integer i : integerArray2) System.out.print(i+“ “); A. 100 1 30 50 B. 100 1 C. 100 30 D. 100 1 30 E.

26、600 1 F. 600 30 G. 600 1 30 H. A compile time error will be generated. I. A runtime exception will be thrown.(分数:3.00)A.B.C.D.E.F.G.H.I.21.What line will produce a compiler error? A. double numbers; B. double numbers; C. double numbers = 1,2,3,7,8,9,4,5,6; D. double numbers = 1,2,3,7,8,4,5,6,9; E. d

27、ouble numbers = new double7; F. double numbers = new double; G. double numbers = new double732;(分数:4.00)A.B.C.D.E.F.G.22.What is the value of the variable sum at the end of this code segment? int square=new int33; for(int i=0;i3;i+) squareii=5; int sum=0; for(int i=0;i3;i+) for(int j=0;j3;j+) sum+=s

28、quare ij; A. 0 B. 5 C. 10 D. 15 E. 20 F. 25 G. 30 H. 35 I. 40 J. 45 K. 50 L. It will generate a compiler error.(分数:4.00)A.B.C.D.E.F.G.H.I.J.K.L.23.The following code segment is valid. True or false? int square = new int2; square0 = new int5; square1=new int3; A. True B. False(分数:4.00)A.B.24.What can

29、 be stored in an ArrayList? A. Primitives B. Objects C. Standard arrays D. Enums(分数:4.00)A.B.C.D.25.What is the value of the size variable at the completion of this code segment?ArrayList Object sampleArrayList = new ArrayList Object();sampleArrayList.add(new Object();sampleArrayList.ensureCapacity(

30、15);sampleArrayList.add(new Object();int size = sampleArrayList.size(); A. 0 B. 1 C. 2 D. 10 E. 15 F. A compile time error will be generated. G. A runtime exception will be thrown.(分数:4.00)A.B.C.D.E.F.G.26.For standard situations what is typically the best type of array to use? A. ArrayList B. One-d

31、imensional array C. Multi-dimensional array(分数:4.00)A.B.C.27.What is the output of the following code segment?ArrayList String sampleArrayList = new ArrayList String();sampleArrayList.add (“One“);sampleArrayList.add (“Two“);sampleArrayList.add (1, “Three“);for(String s : sampleArrayList) System.out.

32、print(s+“ “); A. One Two Three B. One Three Two C. Three One Two D. One Three E. Three Two F. A compile time error will be generated. G. A runtime exception will be thrown.(分数:4.00)A.B.C.D.E.F.G.28.The ArrayList class is part of what Java package? A. java.lang B. java.util C. javax.tools D. javax.sw

33、ing(分数:4.00)A.B.C.D.29.What array type has the most overhead? A. One-dimensional array B. Multi-dimensional array C. ArrayList(分数:4.00)A.B.C.30.What best describes the result of the following code segment? The ArrayList sampleArrayList has already been declared and initialized.int i = 63;sampleArray

34、List.add(i); A. The int is successfully placed into the ArrayList. B. The int is converted to an Integer via autoboxing and then placed into the ArrayList. C. null is placed into the ArrayList. D. A compile time error will be generated. E. A runtime exception will be thrown.(分数:4.00)A.B.C.D.E.计算机 Ja

35、va认证-理解方法和变量的作用域、数组编程答案解析(总分:100.00,做题时间:90 分钟)一、B不定项选择题/B(总题数:30,分数:100.00)1.A method needs to be created that accepts an array of floats as an argument and does not return any variables. The method should be called setPoints. Which of the following method declarations is correct? A. setPoints(floa

36、t points) . B. void setPoints(float points) . C. void setPoints(float points) . D. float setPoints(float points) .(分数:3.00)A.B.C. D.解析:void 必须用于不返回任何数据的方法。A、B 和 D不正确。A 不正确,因为它缺少返回类型。如果方法不打算返回一个变量,它仍然要使用 void。B 不正确,因为它没有 float数组作为参数。D 不正确,因为它使用了错误的返回类型。2.When the void keyword is used, which of the fo

37、llowing statements are true? (Choose all that apply.) A. A return statement with a value following it must be used. B. A return statement with a value following it can optionally be used. C. A return statement with a value following it should never be used. D. A return statement by itself must be us

38、ed. E. A return statement by itself can optionally be used. F. A return statement by itself should never be used. G. A return statement must be omitted. H. A return statement can optionally be omitted. I. A return statement should never be omitted.(分数:3.00)A.B.C. D.E. F.G.H. I.解析:当使用 void时,表示方法没有返回数

39、据。C 正确,因为返回任何数据都是无效的。E 正确,因为自己选择性地使用 return是有效的。H 正确,因为 return语句也可以选择性地忽略。A、B、D、F、G 和 I不正确。A 和 B不正确,因为 void关键字意味着你不能返回值。D、F、G 和 I不正确,因为当使用 void时,return 语句是可选的。3.Given the SampleClass, what is the output of this code segment?SampleClass s = new SampleClass();s.sampleMethod(4.4, 4);public class Sample

40、Class public void sampleMethod(int a, double b) System.out.println(“Method 1“);public void sampleMethod(double b, int a) System.out.println(“Method 2“); A. Method 1 B. Method 2 C. Method 1 Method 2 D. Method 2 Method 1 E. Compiler error(分数:3.00)A.B. C.D.E.解析:这是一个具有重载方法的类的示例。因为传递 double和 int基本数据类型作为参

41、数,所以它会调用第二个方法。A、C、D 和 E不正确,因为这是正确的代码,并且只调用第一个方法。4.Given the class FloatNumber and method addHalf, what is the output if the following code segment is executed?public class FloatNumber float number;public FloatNumber(float number this.number = number;floatgetNumber( retum number;void setNumber(float

42、number) this.number = number;void addHalf(FloatNumber value) value.setNumber(value.getNumber()+(value.getNumber()/2f);/* CODE SEGMENT */FloatNumber value = new FloatNumber(1f);addHalf(value);System.out.println(“value =“+value.getNumber(); A. value = 1 B. value = 1.5 C. value = 2 D. value = 0(分数:3.00

43、)A.B. C.D.解析:FloatNumber 对象是通过引用传递的。因此,方法改变了其值,当代码返回原来调用的代码段时,此改动依然存在。A、C 和 D不正确。A 不正确,因为 FloatNumber是通过引用传递的。如果它是 float基本数据类型,这将是正确答案。C 和 D不正确,无论这个变量是引用传递还是值传递。5.Objects are passed by _. A. Value B. Sum C. Reference D. Pointer(分数:3.00)A.B.C. D.解析:对象总是通过引用传递。A、B 和 D不正确。A 不正确,因为基本数据类型只能通过值传递。B 不正确,因为

44、 Sum不是一个真正的术语。D 不正确,因为 Java不使用术语 pointer。6.Primitives are passed by _. A. Value B. Sum C. Reference D. Pointer(分数:3.00)A. B.C.D.解析:基本数据类型总是通过值传递。B、C 和 D不正确。B 不正确,因为 Sum不是一个真正的术语。C 不正确,因为对象只能通过引用传递。D 不正确,因为 Java不使用术语 pointer。7.You need to create a class to store information about books contained in a

45、 library. What variable scope is best suited for the variable that will store the title of a book? A. Local variable B. Static variable C. Global variable D. Method parameter E. Instance variable(分数:3.00)A.B.C.D.E. 解析:在存储与书相关信息的类中,你希望将书的标题存储到将驻留在对象整个生命周期内的一个变量中。A、B、C 和 D不正确。A 不正确,因为局部变量最适合于只在短时间内使用的

46、数据。B 不正确,因为静态或者类变量最适合于类的所有对象都需要访问的数据。C 不正确,因为在 Java中不建议全局变量,并且在这种情形下是不合理的。D 不正确,因为它只能用于方法。8.Given the SampleClass, when the following code segment is executed, what is the value of the instance variable size?SampleClass sampleClass = new SampleClass(5);public class SampleClass private int size;publi

47、c SampleClass(int size) size = size; A. 0 B. 1 C. 5 D. Compiler error E. Runtime error(分数:3.00)A. B.C.D.E.解析:实例变量被参数隐藏,因为它们都具有相同的名字。要设置 size为 5,必须使用this.size=size。该实例变量为 0,因为这是赋予实例变量的默认值。B、C、D 和 E不正确。B 不正确,因为默认情况下,实例变量设置为 0,而不是 1。D 和 E不正确,因为该代码是有效的。9.Given the SampleClass, what is the output of this code segment?SampleClass sampleClass = new SampleClass();public class SampleClass private int size;private int priority;public SampleClass() super();System.out.println(“Using default values“);public SampleC

copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
备案/许可证编号:苏ICP备17064731号-1