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
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Material Type: Quiz; Class: OBJECT-ORIENTED PROG I; Subject: Computer Science; University: University of Maryland; Term: Unknown 1989;
Typology: Quizzes
1 / 1
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.)