=========================preview======================
(COMP201)summer06_midterm_solution.pdf
Back to COMP201 Login to download
======================================================
THE HONG KONG UNIVERSITY OF SCIENCE & TECHNOLOGY
COMP 201: Java Programming

Summer 2006
Midterm Examination
15:00-17:00 July 12, LTD

Student Name: SOLUTION Email Address: ___________________

Student ID: Lab Section:

Instructions:
1.
This is a closed-book, closed-notes examination.

2.
Check that you have all of the 11 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. Both arrays and ArrayLists can have int as the type of their elements.
2 Every method of a class can access a static field of the class.
3 Overlapping scopes will cause compilation errors.
4 String is an immutable class.
5 A variable of the char type cannot be converted to the inttype.
6 The Scanner class does not exist in Java versions prior to 5.0.
7 All Java methods are call-by-value, instead of call-by-reference.
8 Java uses is null to test if an object variable is a null reference.
9 The paint method of JApplet gets context information from a Graphics2D object.
10 All fields in an interface are constants.

Circle your answers (one circle per question) in the following answer sheet:
1 2 3 4 5 6 7 8 9 10
F T F T F T T F T T

Section II. Multiple-Choice Questions (10 questions, 3 points per question) Note: Select only one choice as your answer for each question
1.
What will happen when a single class has several methods with the same name but different parameter
types?
A) Overriding
B) Overloading
C) Polymorphism
D) Cast


2.
Which of the following is a compilation error?
A) Round-off
B) Overflow
C) Incompatible types
D) Infinite loops


3.
Which of the following is a legal Java identifier?
A) assert
B) name-1
C) 2run
D) instance


4.
Which of the following invokes the javadoc utility from a command shell?
A) javadoc *.java;
B) javadoc MyClass;
C) javadoc *.java
D) javadoc MyClass


5.
Which of the following will not cause side effects?
A) Changing the state of an explicit parameter
B) Changing the state of the implicit parameter
C) Changing the state of System.in
D) Changing the state of System.out


6.
When a graphical component in a Java application is displayed for the first time, which of the following
method is automatically called?
A) draw
B) paint
C) paintComponent
D) setVisible


7.
Given int[] data = new int[10], which of the following is equal to 10?
A) data.size
B) data.size()
C) data.length
D) data.length()


8.
Which of the following statements about type conversion is true?



A. Conversion between int and doublecan be done implicitly.

B. Conversion from a double to a String requires cast.

C. Conversion from a