面向对象编程基础习题及答案
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