Professional Documents
Culture Documents
Sample Quiz1 Answers
Sample Quiz1 Answers
CS 151
computer's RAM
b. Reserved words
c. Symbolic names made up by the programmer whose values cannot be changed
d. Operators that perform operations on one or more operands
ANS: A
3. Byte code instructions are:
a. Another name for source code
b. Syntax errors
c. Machine code instructions
d. Read and interpreted by the JVM
ANS: D
4. The purpose of validating the results of the program is:
a. To create a model of the program
b. To correct syntax errors
c. To correct runtime errors
d. To determine if the program solves the original problem
ANS: D
5. Each method manipulates one or more:
a. Attributes
b. Other methods
c. Classes
d. Objects
ANS: A
6. Key words are:
a. The data names in your program
b. Words that have a special meaning in the programming language
c. Symbols or words that perform operations on one or more operands
d. Words or names defined by the programmer
ANS: B
ECC
Niko ulevski
CS 151
y = 54.9;
b. float y;
double z;
z = 934.21;
y = z;
c. float w;
w = 1.0f;
ECC
Niko ulevski
CS 151
d. double v;
v = 1.0f;
ANS: C
12. What will be displayed as a result of executing the following code?
int x = 5, y = 20;
x += 32;
y /= 4;
System.out.println("x = " + x + ", y = " + y);
a.
b.
c.
d.
x = 32, y = 4
x = 9, y = 52
x = 37, y = 5
x = 160, y = 80
ANS: C
13. What will be the value of z as a result of executing the following code?
int x = 5, y = 28;
float z;
z = (float) (y / x);
a. 5.0
b. 5.6
c. 3.0
d. 5
ANS: A
14. Which of the following is not a valid comment statement?
a. // comment 1
b. /* comment 2 */
c. */ comment 3 /*
d. /** comment 4 */
ANS: C
15. What would be displayed as a result of the following code, assuming x has been declared an int?
x = 578;
System.out.print("There are " +
x + 5 + "\n" +
"hens in the hen house.");
a. There are 583 hens in the hen house.
b. There are 5785 hens in the hen house.
c. There are x5\nhens in the hen house.
d. There are 5785
hens in the hen house.
ANS: D
ECC
Niko ulevski
CS 151
16. To display the output on the next line, you can use the println method or use the escape sequence,
25 - 7 * 3 + 12 / 3
a.
b.
c.
d.
6
8
10
12
ANS: B
18. What will be displayed after the following statements have been executed?
= 32;
= " + x +
y = " + y +
z = " +z);
ANS: C
19. What will be the value of z after the following statements have been executed?
int x = 4, y = 33;
double z;
z = (double) (y / x);
a. 8.25
b. 4
c. 8
d. 8.0
ANS: D
20. What is the result of the following expression?
17 % 3 * 2 - 12 + 15
a. 7
b. 8
ECC
Niko ulevski
CS 151
c. 12
d. 105
ANS: A
21. Which of the following is a valid Java statement?
a. String str = 'John Doe';
b. string str = 'John Doe';
c. string str = "John Doe";
d. String str = "John Doe";
ANS: D
Answers:
1
B
ECC
2
A
3
D
4
D
5
A
6
B
7
C
8
D
9 10 11 12 13 14 15 16 17 18 19 20 21
D D C C A C D A B C D A D
Niko ulevski