Get 2 days of unlimited access
Study Guides (350,000)
US (190,000)
UMD (10,000)
CMSC (700)
Midterm

CMSC 131 Study Guide - Midterm Guide: Instance VariableExam


Department
Computer Science
Course Code
CMSC 131
Professor
Fawzi Emad
Study Guide
Midterm

This preview shows pages 1-2. to view the full 8 pages of the document.
1
University of Maryland College Park
Dept of Computer Science
CMSC131 Spring 2011
Midterm II
First Name (PRINT): ___________________________________________________
Last Name (PRINT): ___________________________________________________
University ID: _________________________________________________________
Section/TAName: _________________________________________________________
I pledge on my honor that I have not given or received any unauthorized assistance on this examination.
Your signature: _____________________________________________________________
Instructions
This exam is a closed-book and closed-notes exam.
Total point value is 100 points.
The exam is a 50 minutes exam.
Please use a pencil to complete the exam.
WRITE NEATLY. If we cannot understand your answer, we will not grade it (i.e., 0 credit).
Grader Use Only
#1
Problem 1 (General Questions)
(16)
#2
Problem 2 (Memory Map)
(8)
#3
Problem 3 (Parsing/Exception)
(20)
#4
Problem 4 (Class Definition)
(56)
Total
Total (100)
(100)

Only pages 1-2 are available for preview. Some parts have been intentionally blurred.

2
Problem 1 (16 pts)
1. (1 pt) Name one class discussed in class that is immutable. ___________________
2. (1 pt) When should we define a method as static?
3. (1 pt) What is the default value of reference instance variables of a class? ___________________
4. (2 pts) When is space for a local integer variable allocated and when is it recovered?
5. (2 pts) Why do we never use == to compare floating point numbers?
6. (1 pt) When is the finally block associated with exceptions executed?
7. (1 pt) In which area of memory are objects created? ___________________
8. (1 pt) When should we define a constant as a static constant? In other words, when should we use
static final vs. final while defining a constant?
9. (6 pts) Based on the following class, indicated whether the statements below are valid or invalid. Circle
your answer.
public class Computer {
private String make;
public Computer(String makeIn) { make = makeIn; }
public void setMake(String makeIn) { make = makeIn; }
public static void info() { System.out.println("Computer Sys"); }
}
a. Computer c1 = new Computer("sun"); // VALID / INVALID
c1.setMake("mars");
b. Computer c2 = null; // VALID / INVALID
c2.setMake("moon");
c. Computer c3 = new Computer("earth"); // VALID / INVALID
Computer.setMake("saturn");
d. Computer c4 = new Computer("venus"); // VALID / INVALID
c4.info();
e. Computer c5 = new Computer("jupiter"); // VALID / INVALID
c5.make = "uranus";
f. Computer.info(); // VALID / INVALID
You're Reading a Preview

Unlock to view full version

Only pages 1-2 are available for preview. Some parts have been intentionally blurred.

3
Problem 2 (8 pts)
Draw a memory diagram showing both the stack and the heap at the moment this program reaches the point
marked /* HERE */
public class MemoryMap {
public static void filter(StringBuffer state, int by) {
state.append("now");
by = 333;
process(state, by);
}
public static void process(StringBuffer first, int last) {
first = null;
last = 200;
/* HERE */
}
public static void main(String[] args) {
StringBuffer orig = new StringBuffer();
orig.append("cold");
int val = 100;
filter(orig, val);
}
}
Stack Heap
args
Stack Bottom
You're Reading a Preview

Unlock to view full version