Practice Midterm Exam 2 on Object Oriented Programming I | CMSC 131, Exams of Computer Science

Material Type: Exam; Professor: Padua-Perez; Class: OBJECT-ORIENTED PROG I; Subject: Computer Science; University: University of Maryland; Term: Unknown 1989;

Typology: Exams

Pre 2010

Uploaded on 02/13/2009

koofers-user-tr8
koofers-user-tr8 🇺🇸

9 documents

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CMSC131
Spring 2004
Midterm #2
Name: _____________________
Student ID: _________________
Section: ____________________
Problem 1 (20 points) General Questions.
1. Is it possible in Java to create an array of size 0?
Circle Yes or No.
2. Suppose you have the following comment:
/*
*
The function computes the average
*
*/
Modify the comment and turn it into a javadoc comment.
3. What is the difference between System.out.println() and System.out.print()?
4. Write the line of Java code that designates that the code in a specific file belongs to the 'oopi'
package.
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 (20)
#2 a (8)
b (7)
#2 (15)
#3 (25)
#4 (40)
Total (100)
pf3
pf4
pf5
pf8

Partial preview of the text

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

CMSC

Spring 2004

Midterm

Name: _____________________ Student ID: _________________ Section: ____________________ Problem 1 (20 points) General Questions.

  1. Is it possible in Java to create an array of size 0? Circle Yes or No.
  2. Suppose you have the following comment: /* * The function computes the average * */ Modify the comment and turn it into a javadoc comment.
  3. What is the difference between System.out.println() and System.out.print()?
  4. Write the line of Java code that designates that the code in a specific file belongs to the 'oopi' package. 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 (20) #2 a (8) b (7) #2 (15) #3 (25) #4 (40) Total (100)
  1. Write the line of code that converts the integer variable i to a String that represents that integer?
  2. Write the statement that will allow us to access any class present in the java.util package within a Java program.
  3. Which of the following situations will occur when an exception occurs and it is not handled? Circle your choice(s). a. The debugger is invoked in order to take care of the exception. b. The program is terminated (stops executing), and the call stack is displayed. c. An infinite loop will occur.
  4. Describe two exceptions discussed in lecture. Describing two situations causing those exceptions will be considered a valid answer (i.e., you do not have to know the precise names of the exceptions.)
  5. Can you have more than one class per file in Java? If there are any restrictions, what are they?
  6. Given the following code fragment: String name1 = null; String name2 = ""; Is the expression (name1 == name2) true or false?

Problem 3 (25 points) On the following page write a memory diagram representing the variables, and objects in the callstack and heap at the point where execution reaches the point marked as “STOP HERE”. Notice this point is before the method returns (that is, we also want to see the values of the local variables within “process” before it exits.) public class Prob3 { public void process(String[] data, int theIndex, String theInfo) { data[theIndex] = theInfo; theIndex = 1; // STOP HERE } public Prob3() { String[] strValues = new String[4]; strValues[1] = new String("House"); strValues[2] = new String("Permit"); String info = new String("Warning"); int index = 0; process(strValues, index, info); } public static void main(String[] args) { Prob3 prob3 = new Prob3(); } } Fill in the memory diagram template on the next page

Fill in memory diagram here Call Stack Heap

Extra page for code writing

Extra page for code writing