面向对象编程基础习题及答案
PartI.Choice Questions (1pt for each四颗糖的故事 question).
1.To add a to b and store result in b, you write (Note: Java is ca-nsitive)
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. class
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
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. "a"
C. '\000a'
关于年兽的传说D. None of the above.
10.Which of the following statement prints smith\?
A. System.out.println("smith\");
B. System.out.println("smith\\exam1\\");
C. System.out.println("smith\"exam1\"");
D. System.out.println("smith"\exam1"\");
11.Suppo i is an int type variable. Which of the following statements display the character who 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. micolon (;)
C. period (.)
D. closing brace
16.The assignment operator in Java is __________.
A. :=
B. =
C. = =
D. <-
17.Suppo 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 raid 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 the 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 = "5";
D. char c = "344";
22.Note that the Unicode for character A is 65. The expression "A" + 1 evaluates to ________.
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;
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("month is " + month);
}
}
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, becau 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("y is " + y);
}
}
A. y is 0.
B. y is 1 becau x is assigned to y first.
C. y is 2 becau x + 1 is assigned to x and then x is assigned to y.
D. The program has a syntax error since x is redeclared in the statement int y = x = x + 1.