第一范文网 - 专业文章范例文档资料分享平台

面向对象编程基础习题及答案

来源:用户分享 时间:2025/5/23 15:52:28 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

public static void main(String[] args) { for (int i = 1; i < 10; i++) { int k = 3;

nPrint(\

}

System.out.println(\ }

A. The code has a syntax error because k is not defined in

System.out.println(\B. The code prints k is 0. C. The code prints k is 1. D. The code prints k is 2. E. The code prints k is 3.

76. Analyze the following code.

public class Test {

public static void main(String[] args) { int n = 2;

xMethod(n);

System.out.println(\ }

void xMethod(int n) { n++; } }

A. The code has a syntax error because xMethod does not return a value.

B. The code has a syntax error because xMethod is not declared static.

C. The code prints n is 1. D. The code prints n is 2.

E. The code prints n is 3.

77. Which of the following is not an advantage of using methods.

A. Using methods makes program run faster. B. Using methods makes reusing code easier.

C. Using methods makes programs easier to read.

D. Using methods hides detailed implementation from the clients.

第 17 页 共 34 页

78. Which of the following is a possible output for 50 * Math.random()?

A. 0 B. 50 C. 100 D. 500

E. A and B.

79. Which of the following method results in 8.0?

A. Math.round(8.5) B. Math.rint(8.5)

C. Math.ceil(8.5) D. Math.floor(8.5) E. b and d.

80. Which of the following method returns the sine of 90 degree?

A. Math.sine(90)

B. Math.sin(90) C. Math.sin(PI)

D. Math.sin(Math.toRadian(90)) E. Math.sin(Math.PI)

81. Suppose array a is int[] a = {1, 2, 3}, what is a[0] - a[2]?

A. 1 B. 2

C. 3

D. None of the above

82. An array can be used in which of the following ways?

A. As a local variable

B. As a parameter of a method C. As a return value of a method D. All of the above

83. Which of the following are valid array declarations?

A. char[] charArray = new char[26];

B. int[] words = new words[10];

C. char[] charArray = \D. double[3] nums = {3.5, 35.1, 32.0}; E. None of the above 84. Consider the following code fragment:

int[] list = new int[10];

for (int i = 0; i <= list.length; i++) { list[i] = (int)(Math.random() * 10); }

Which of the following statements is true? A. list.length must be replaced by 10

第 18 页 共 34 页

B. The loop body will execute 10 times, filling up the array with random numbers.

C. The loop body will execute 10 times, filling up the array with

zeros.

D. The code has a runtime error indicating that the array is out

of bound.

85. Assume the signature of the method xMethod is as follows.

public static void xMethod(double[] a)

Which of the following could be used to invoke xMethod? A. xMethod(5);

B. xMethod({3, 4});

C. xMethod(new int[2]); D. xMethod(new double[2]); E. None of the above.

86. Given the following statement

int[ ] list = new int[10]; list.length has the value

A. 10 B. 9

C. The value depends on how many integers are stored in list. D. None of the above.

87. Given the following statement

int[ ] list = new int[10];

A. The array variable list contains a memory address that refers to an array of 10 int values.

B. The array variable list contains a memory address that refers

to an array of 9 int values. C. The array variable list contains ten values of type int. D. The array variable list contains nine values of type int. E. None of the above. 88. Analyze the following code:

public class Test {

public static void main(String[] args) { int[] x = new int[5]; int i;

for (i = 0; i < x.length; i++) x[i] = i;

System.out.println(x[i]); }

第 19 页 共 34 页

}

A. The program displays 0 1 2 3 4. B. The program displays 4.

C. The program has a runtime error because the last statement in the main method causes ArrayIndexOutOfBoundsException.

D. The program has syntax error because i is not defined in the last statement in the main method.

89. Given the following declaration:

int[ ][ ] m = new int[5][6];

Which of the following statements is true?

A. The name m represents a two-dimensional array of 30 int values. B. m[2][4] represents the element stored in the 2nd row and the 4th column of m.

C. m.length has the value 6. D. m[0].length has the value 5. 90. In the following code, what is the printout for list2?

class Test {

public static void main(String[] args) { int[] list1 = {3, 2, 1}; int[] list2 = {1, 2, 3}; list2 = list1;

list1[0] = 0; list1[1] = 1; list2[2] = 2;

for (int i = list2.length - 1; i >= 0; i--) System.out.print(list2[i] + \ } }

A. 1 2 3 B. 3 2 1 C. 0 1 2 D. 2 1 0 E. 0 1 3.

91. Analyze the following code:

public class Test {

public static void main(String[] args) { int[] x = {0, 1, 2, 3, 4, 5}; xMethod(x, 5); }

第 20 页 共 34 页

搜索更多关于: 面向对象编程基础习题及答案 的文档
面向对象编程基础习题及答案.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c8zw199vcmo44p5d1brid_5.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top