云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 面向对象编程基础习题及答案

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

  • 62 次阅读
  • 3 次下载
  • 2025/12/3 14:38:28

double, but assigned with integer value 0.

B. The program never stops because d is always 0.1 inside the loop. C. The program may not stop because of the phenomenon referred

to as numerical inaccuracy for operating with floating-point numbers. D. After the loop, sum is 0 + 0.1 + 0.2 + 0.3 + ... + 1.9 61. What is y after the following for loop statement is executed?

int y = 0;

for (int i = 0; i < 10; ++i) {

y += 1; }

A. 9 B. 10 C. 11

D. 12

E. None of the above.

62. What balance after the following code is executed?

int balance = 10; while (balance >= 1) {

if (balance < 9) continue; balance = balance - 9; }

A. -1 B. 0 C. 1 D. 2

E. The loop does not end

63. What is the value of balance after the following code is executed?

int balance = 10;

while (balance >= 1) {

if (balance < 9) break; balance = balance - 9; }

A. –1 B. 0 C. 1

第 13 页 共 34 页

D. 2

E. None of the above 64. What is x after evaluating

x = (2 > 3) ? 2 : 3;

A. 2 B. 3 C. 4

D. None of the above

65. The signature of a method consists of ____________.

A. method name

B. method name and parameter list

C. return type, method name, and parameter list D. parameter list

66. A variable that is declared inside a method is called ________ variable.

A. a static B. an instance C. a local

D. a global E. a class

67. Each Java class must contain a main method.

A. true B. false 68. What is (int)Math.random()?

A. 0 B. 1

C. both 0 and 1 are possible D. None of the above 69. Analyze the following code.

public class Test {

public static void main(String[] args) { System.out.println(m(2)); }

public static int m(int num) { return num; }

public static void m(int num) { System.out.println(num); }

第 14 页 共 34 页

}

A. The program has a syntax error because the two methods m have

the same signature.

B. The program has a syntax error because the second m method is defined, but not invoked in the main method. C. The program runs and prints 2 once. D. The program runs and prints 2 twice. 70. Analyze the following code:

class Test {

public static void main(String[] args) { System.out.println(xMethod((double)5)); }

public static int xMethod(int n) { System.out.println(\ return n; }

public static long xMethod(long n) { System.out.println(\ return n; } }

A. The program displays int followed by 5.

B. The program displays long followed by 5.

C. The program runs fine but displays things other than given in

A and B. D. The program does not compile. E. None of the above. 71. Analyze the following code:

public class Test {

public static void main(String[] args) { System.out.println(xMethod(5, 500L)); }

public static int xMethod(int n, long l) { System.out.println(\ return n; }

第 15 页 共 34 页

public static long xMethod(long n, long l) { System.out.println(\ return n; } }

A. The program displays int, long followed by 5. B. The program displays long, long followed by 5.

C. The program runs fine but displays things other than given in

a and b.

D. The program does not compile because the compiler cannot distinguish which xmethod to invoke.

72. You may have a return statement in a void method.

A. true B. false

Note: Questions 73–75 are based on the following method:

static void nPrint(String message, int n) { while (n > 0) {

System.out.print(message); n--; } }

73. What is the printout of the call nPrint(\

A. aaaaa B. aaaa C. aaa

D. invalid call

74. What is k after invoking nPrint(“A message”, k+1)?

int k = 2;

nPrint(\ A. 0 B. 1 C. 2

D. 3

E. None of the above.

75. Analyze the following code.

第 16 页 共 34 页

搜索更多关于: 面向对象编程基础习题及答案 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

double, but assigned with integer value 0. B. The program never stops because d is always 0.1 inside the loop. C. The program may not stop because of the phenomenon referred to as numerical inaccuracy for operating with floating-point numbers. D. After the loop, sum is 0 + 0.1 + 0.2 + 0.3 + ... + 1.9 61. What is y after the following for loop statement is executed?

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com