
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
Material Type: Quiz; Class: OBJECT-ORIENTED PROG I; Subject: Computer Science; University: University of Maryland; Term: Unknown 1989;
Typology: Quizzes
1 / 1
This page cannot be seen from the preview
Don't miss anything!

Quiz 4 Solution
Six local memory locations are created on the stack and four (string) objects are created in the heap. The variables a and b point to different strings. The variable c points to its own copy of a string object. The variables d and e end up pointing to the same object. The local variable temp is created for the value 20.
Note: Some Java optimizers would allow a and b to point to the same memory location because the string is known at compile time. That is, the assignment operator (=) was applied directly to a string without the use of "new". (Such an optimization is safe because strings are immutable, which means they cannot be inadvertently changed.) However, no other objects can be created without the use of “new.” Thus, in the general case (for all other types of objects), a and b would point to different objects, as we have shown here. (In this class, you need not worry about optimization, so the solution below is generally applicable.)