=========================preview======================
(COMP201)summer07_midterm_solution.pdf
Back to COMP201 Login to download
======================================================
THE HONG KONG UNIVERSITY OF SCIENCE & TECHNOLOGY
COMP 201: Java Programming
Summer 2007
Midterm Examination
10:00-12:00 July 11, LTB
Student Name: Email Address: ____________________
Student ID: SOLUTION Lab Section:
Instructions:
1. This is a closed-book, closed-notes examination.
2. Check that you have all of the 12 pages (including this cover page).
3. Text in Courier is Java source code.
4. Answer questions in the designated space.
5. Make sure your final answers are clearly recognizable.
Section
Score / Full Score
I
/20
II
/30
III
/30
IV
/20
Total
/100
Section I. True/False Questions (10 questions, 2 points per question)
1.
2
3
4
5
6
7
8
9
10
Java source code is executed on a Java Virtual Machine.
You can always assign an int value to a long variable without loss of information.
A continue statement can be used only in a loop.
Double is an immutable class.
You can use any Java class in your program without explicitly importing it.
If a method is declared public in the superclass, you may declare the method private in the subclass.
A protected class can be accessed by a subclass in a different package.
You can use the new operator to create an object of a final class.
A data field can be declared abstract.
Every Java class has a no-arg default constructor.
Circle your answers (one circle per question) in the following answer sheet:
1
2
3
4
5
6
7
8
9
F
T
T
T
T
F
T
T
F
10
F
Section II. Multiple-Choice Questions (10 questions, 3 points per question)
Note: Select only one choice as your answer for each question
1. Which of the following keywords must be used to define a constant?
A) const
B) final
C) public
D) static
2. Which of the following classes has the method parseInt?
A) Integer
B) Scanner
C) String
D) System
3. To append data to an existing file, which of the following object do you construct on the file?
A) new FileOutputStream(out.dat);
B) new FileOutputStream(out.dat, false);
C) new FileOutputStream(out.dat, true);
D) new PrintWriter(out.dat);
4. Which of the following evaluates to 201?
A) COMP201.substring(3,6);
B) COMP201.substring(3,7);
C) COMP201.substring(4,6);
D) COMP201.substring(4,7);
5. Which of the following can not be the data type of the switch expression in a switch statement?
A) boolean
B) byte
C) char
D) short
6. Suppose A is a non-abstract class and B is an abstract subclass of A. Both A and B have default constructors. Which of the following statements is correct?
A) A a = new A();
B) A a = new B();
C) B b = new A();
D) B b = new B();