Docsity

Object Oriented Programming I- Midterm Exam 1 | CMSC 131, Exams of Computer Science

Toggle sidebar
bg1
CMSC 131
Object Oriented Programming I
Midterm Exam #1
March 3, 2004
Name: _________________________________
Problem 1 (20 points) General Questions:
a. What is the name of the IDE you have been using for
this class?
b. Is a parameter an instance variable? (Answer Yes or
No)
c. Which of the following are valid names for Java
variables? (Circle valid variable names)
10 dog 77temperature abc15
d. Is RAM classified as main or secondary memory?
e. Are hard disks volatile or non-volatile memory?
f. Are all reference variables local variables? (Yes or No)
Grader Use Only:
#1 a (2)
b (2)
c (2)
d (2)
e (2)
f (2)
g (2)
h (2)
i (2)
j (2)
#1 subtotal (20)
#2 a (6)
b (6)
c (6)
d (11)
#2 subtotal (29)
#3 (27)
#4 a (12)
b (12)
#4 subtotal (24)
Total (100)
pf3
pf4
pf5
pf8

Partial preview of the text

Download Object Oriented Programming I- Midterm Exam 1 | CMSC 131 and more Exams Computer Science in PDF only on Docsity!

CMSC 131

Object Oriented Programming I

Midterm Exam

March 3, 2004

Name: _________________________________

Problem 1 (20 points) General Questions:

a. What is the name of the IDE you have been using for

this class?

b. Is a parameter an instance variable? (Answer Yes or

No)

c. Which of the following are valid names for Java

variables? (Circle valid variable names)

10 dog 77temperature abc

d. Is RAM classified as main or secondary memory?

e. Are hard disks volatile or non-volatile memory?

f. Are all reference variables local variables? (Yes or No)

Grader Use Only:

#1 a (2)

b (2)

c (2)

d (2)

e (2)

f (2)

g (2)

h (2)

i (2)

j (2)

#1 subtotal (20)

#2 a (6)

b (6)

c (6)

d (11)

#2 subtotal (29)

#4 a (12)

b (12)

#4 subtotal (24)

Total (100)

g. What is the name of the entity within the Java Virtual machine that is responsible

for collecting objects that have no more reference variables that reference them?

h. Can we declare two instance variables with the same name in a class? (Yes or No)

i. Are instance variables initialized to a default value? (Yes or No)

j. Which of the following are valid primitive types in Java? (Circle valid types)

int boolean float scientific

Problem 2 (29 points) Understanding Code

fri.setHumidity(70); maxTemp = 110; // Draw the memory diagram when code execution reaches this point } }

a. (6 points) What is the output produced by executing the following code segment:

ProbTwo prob2 = new ProbTwo();

prob2.one(8, 4);

b. (6 points) What is the output produced by executing the following code segment:

ProbTwo prob2 = new ProbTwo();

prob2.two(5.0, 10.0, 7.0);

prob2.two(5.0, 8.0, 9.0);

c. (6 points) What is the the output produced by executing the following code segment:

ProbTwo prob2 = new ProbTwo();

prob2.three(3);

d. (11 points) For this part you will draw a memory diagram. The following is a

memory diagram example:

int a = 10;

String m = new String("Hello");

Draw a memory diagram that represents the state of the variables monday, friday,

maximum, mon, fri, maxTemp and all objects after the following code segment has

been executed, but just before the “four” method returns (that is, we want to see the

values of the local variables within “four” before it exits.)

Weather monday = new Weather(80.0);

Weather friday = new Weather(60.0);

double maximum = 120;

prob2.four(monday, friday, maximum);

a

m

“Hello”

Problem 4 (24 points) Syntax Errors

Circle the pieces of code that have syntax (i.e., compiler) errors in each of the following

code segments.

a. (12 points) There are 6 syntax errors in this code segment.

public class { private area; private boolean int ; poblic void f2( int x, y) { if (x = 3) { System.out.println("Step 1"); } else { System.out.println("Step 2"); } } /* A simple method public void setArea(theArea double) { area = theArea; } }

b. (12 points) There are 3 syntax errors in this code segment.

public class ProbThreeC { private int numBananas; private double gallonsCoffee; public void test( boolean likesMe) { numBananas = gallonsCoffee; gallonsCoffee = numBananas; gallonsCoffee = likesMe; if (numBananas == gallonsCoffee) { System.out.println("hello"); } int a = 0; if ((a = 2) == 3) { System.out.println("hello"); } if ((a == 2) = 3) {

System.out.println("hello"); } } }