=========================preview======================
(COMP1022P)[2013](s)midterm~=4a4435^_88035.pdf
Back to COMP1022P Login to download
======================================================
The Hong Kong University of Science and Technology
COMP1022P: Introduction to Computing with Java
Midterm Examination
Spring 2013

March 21, 2013
19:00 p.m. C 21:00 p.m.
Student Name:
Lecture Section: 1


Student ID: Lab Section:


Instructions:
1.
This is an open-notes examination.

2.
Check that you have all 12 pages including extra pages for rough work.

3.
Write your name, student ID, lecture section, and lab section on this page.

4.
Answer all questions in the space provided with a *PEN*. Writing in pencil will be regarded as draft work and not for submission.


Question Score
1 MC Questions /54
2 Expressions and Operators /16
3 Methods /10
4 Branching /10
5 Loops /10
Total /100

Q1. MC Questions (54%)
Answer the following questions in the space provided. There is only one correct answer for each question. 3 marks for each correct answer.
QUESTION 1 2 3 4 5 6 7 8 9
ANSWER

QUESTION 10 11 12 13 14 15 16 17 18
ANSWER

1. Which of the following is an incorrect way to write a comment in Java source code and as a result would cause a compilation error?
A. int a = 1; //set a to 1//

B. int a = 1; ////set a to 1/

C. int a = 1; /** set a to 1 **/

D. int a = 1; /set a to 1/

2. What is the value of variable b after executing the following statements?
int a = 3;
int b = 5;
int c = 4;

b = (a * b) % c;

A. 3
B. 2
C. 1
D. 0
3. Which of the following statements is invalid?
A. int aBc;

B. int AbC3;

C. double 3abc;

D. double _age;

4. Which of the following statements is invalid?
A. int age;

B. int Age;

C. double age;

D. void age;

5. Which statement defines a constant integer variable c with value 88?
A. int
c = 88;


B.
const int maxHeight = 88;


C.
constant int maxHeight = 88;


D.
final int maxHeight = 88;



6. Which of the following variables will store the value 2.5 after the execution of the statement?
A. int a = 2.5;

B. int
b = 5/2;


C.
double c = 5/2;



D. double d = 0.5 * 5;

7. Which of the following statement(s) produce a runtime error?
A. int x = 0

B. int x = 0;

C. int x = 0; int y = 5/x;

D. int x = 0; int y = x/5;

8. Which of the following is false about Constructors?
A. Constructors cannot be static methods
B. Constructors do not have a return type
C. Constructors must have the same name as the class itself
D. Every class can only have one constructor explicitly declared
9. Consider the following code:
double x = 2.0;

while ( x < 10.0 ) {
x *= 2.5;

}

What is the value of variable x after executing the code?
A. 5.0
B. 12.5
C. 10.0
D. 2.0
10. Suppose Picobot is a class. Consider the following declaration:
Picobot bot = null;
What is the meaning of assigning null to bot?
A. It means that variable bot is finalized
B. It means that variable bot is delet