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

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

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

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

PartI. Choice Questions (1pt for each question).

1. To add a to b and store result in b, you write (Note: Java is case-sensitive)

A. b += a;

B. a = b + a; C. b = A + b; D. a += b;

2. To declare a constant PI, you write

A. final static PI = 3.14159;

B. final float PI = 3.14159; C. static double PI = 3.14159; D. final double PI = 3.14159;

3. To improve readability and maintainability, you should declare _________ instead of using

literal values such as 3.14159. A. variables B. methods

C. constants D. classes

4. To declare an int variable x with initial value 200, you write

A. int x = 200L;

B. int x = 200l; C. int x = 200; D. int x = 200.0;

5. To assign a double variable d to an int variable x, you write

A. x = (long)d

B. x = (int)d; C. x = d;

D. x = (float)d;

6. In Java, the word true is ________.

A. a Java keyword

B. a Boolean literal C. same as value 1

D. same as value 0

7. Which of the Boolean expressions below has incorrect syntax?

A. (true) && (3 > 4) B. !(x > 0) && (x > 0)

C. (x > 0) || (x < 0) D. (x != 0) || (x = 0)

8. Which of the following is the correct expression that evaluates to true if the number x is

between 1 and 100 or the number is negative? A. 1 < x < 100 && x < 0

第 1 页 共 34 页

B. ((x < 100) && (x > 1)) || (x < 0) C. ((x < 100) && (x > 1)) && (x < 0) D. (1 > x > 100) || (x < 0)

9. Which of the following is the correct expression of character a?

A. 'a'

B. \

C. '\\000a'

D. None of the above.

10. Which of the following statement prints smith\\exam1\\test.txt?

A. System.out.println(\

B. System.out.println(\C. System.out.println(\

D. System.out.println(\

11. Suppose i is an int type variable. Which of the following statements display the character

whose Unicode is stored in variable i? A. System.out.println(i); B. System.out.println((char)i); C. System.out.println((int)i); D. System.out.println(i + \12. The Unicode of 'a' is 97. What is the Unicode for 'c'?

A. 96

B. 97 C. 98 D. 99

13. Which of the following is a constant, according to Java naming conventions?

A. MAX_VALUE B. Test

C. read D. ReadInt

14. Which of the following assignment statements is illegal?

A. float f = -34; B. int t = 23;

C. short s = 10; D. float f = 34.0;

15. A Java statement ends with a __________.

A. comma (,)

B. semicolon (;) C. period (.) D. closing brace

16. The assignment operator in Java is __________.

A. :=

B. = C. = =

第 2 页 共 34 页

D. <-

17. Suppose m and r are integers. What is the correct Java expression for m / r^2 to obtain a

floating point result value? (r^2 denotes r raised to the power of 2). A. m / r * r B. m / (r * r)

C. 1.0 * m / r * r D. 1.0 * m / (r * r)

18. Which of these data types requires the least amount of memory?

A. float

B. double C. short D. byte

19. Which of the following operators has the highest precedence?

A. casting

B. + C. * D. /

20. An int variable can hold __________.

A. 'x'

B. 93 C. 98.3 D. true E. a and b

21. Which of the following assignment statements is correct to assign character 5 to c?

A. char c = '5';

B. char c = 5; C. char c = \D. char c = \

22. Note that the Unicode for character A is 65. The expression \

A. 66

B. B C. A1

D. Illegal expression

23. The not equal comparison operator in Java is __________.

A. <> B. !=

C. != =

D. ^=

24. If you attempt to add an int, a byte, a long, and a double, the result will be a __________

value.

A. byte B. int; C. long;

第 3 页 共 34 页

D. double;

25. What is the value of (double)5/2?

A. 2; B. 2.5; C. 3;

D. 2.0;

26. What is the value of (double)(5/2)?

A. 2; B. 2.5;

C. 3; D. 2.0;

27. Analyze the following code.

public class Test {

public static void main(String[] args) { int month = 09;

System.out.println(\ } }

A. The program displays month is 09 B. The program displays month is 9 C. The program displays month is 9.0

D. The program has a syntax error, because 09 is an incorrect

literal value. 28. To assign a double variable d to a float variable x, you write

A. x = (long)d

B. x = (int)d; C. x = d;

D. x = (float)d;

29. what is y displayed in the following code?

public class Test1 {

public static void main(String[] args) { int x = 1;

int y = x = x + 1;

System.out.println(\ } }

A. y is 0.

B. y is 1 because x is assigned to y first.

C. y is 2 because x + 1 is assigned to x and then x is assigned

第 4 页 共 34 页

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