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
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 Key
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.
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).
#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?
Answer: If it makes no reference to instance variables.
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?
Answer: Allocated: when the method is called; recovered: when the method finishes
5. (2 pts) Why do we never use == to compare floating point numbers?
Answer: Because floating point numbers are approximations
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?
Answer: We should use static when all instances of the class will use the same constant value
9. (6 pts) Based on the following class, indicated whether the statements below are valid or invalid. Circle
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
c1.setMake("mars");

Unlock to view full version

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

3
b. Computer c2 = null; INVALID
c2.setMake("moon");
c. Computer c3 = new Computer("earth"); INVALID
Computer.setMake("saturn");
d. Computer c4 = new Computer("venus"); VALID
c4.info();
e. Computer c5 = new Computer("jupiter"); INVALID
c5.make = "uranus";
f. Computer.info(); VALID