



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Information about Quiz 3 for the CMSC 131 Summer 2005 course, including instructions, quiz material, and problem sets. The quiz will be based on the exercises provided and will be a written, closed-book exam. topics such as System.out.println vs System.out.print, heap, object vs class, garbage collection, and String manipulation.
Typology: Quizzes
1 / 5
This page cannot be seen from the preview
Don't miss anything!




Problem 1 (General Questions)
int age = 17; double temp = 3.4; String m = “John” + age + “/” + temp;
String r; String s; // Step 1 r = s = “Happy”; // Step r = new String(s); // Step 3 r = null; // Step 4 r = new String(“John”); // Step 5
String k = null; System.out.println(k); System.out.println(k.length());
Problem 2
Problem 3
public static void main(String[] args) { int x; x = 2; String p; p = new String(“Test”); String t = null; // STOP HERE }
Stack Heap
a. Problem 1.j above after finishing Step 5. b. For the following method until we reached the point marked // STOP HERE public class Test { public static void main(String[] args) {
2
i. MethodsExample e = new MethodsExample(); e.printAll("John", 20); ii. MethodsExample e = new MethodsExample(); e.validName("John"); iii. MethodsExample e; e.printName("John"); iv. new MethodsExample().printAll("Mary", 16); v. Revisit i. through iv. but assume all methods of the class MethodsExample are public. vi. Revisit i. through iv. but assume all methods of the class MethodsExample are private. Problem 5 (This was last semester’s quiz) Draw a memory diagram for the following main method, up to point where the comment “STOP HERE” appears. Specify any objects that have been created and the values of the variables a, b, c, d, e, and temp. Remember that we represent references (addresses) with arrows, objects with rectangles, and the null value with a line ended with a perpendicular line. public static void main(String[] args) { String a = "Pop"; String b = "Pop"; double temp = 10; String c = new String("Rock"); String d = new String(c); String e = c; c = d; temp = 20; d = e; // STOP HERE }