2. When does Java know an object is no longer needed? And what happens to an unneeded…
- User
- When does Java know an object is no longer needed? And what happens to an unneeded object's storage? A. The programmer tells Java when an object is no longer needed by calling dispose() on it; the object's memory is released back to the memory pool. B. If there are no references to the object, Java knows the object is no longer needed and automatically returns its memory to the memory pool. C. If there are no references to the object, Java marks it as no longer needed; the memory stays in use until the programmer explicitly returns it to the memory pool. D. Objects, once constructed, stay active until the program terminates, so though the programmer may know an object is it no longer needed, Java does not know this; objects' memory is returned to the memory pool when the program terminates. E. Objects, once constructed, stay active until the method in which they were constructed terminates, so though the programmer may know an object is no longer needed, Java does not know this; objects' memory is returned to the memory pool when the method terminates.
- Assistant
B. If there are no references to the object, Java knows the object is no longer needed and automatically returns its memory to the memory pool.
- User
Use this method when answering the next 2 questions. public static int theValue() { boolean notDone = true; int foundIt = -9; do { System.out.print("Enter score: "); int cntScore = getInt(); //assume getInt() is defined as in lab if (cntScore != -99) { if ((cntScore >= 0) && (cntScore <= 100)) if (cntScore > foundIt) foundIt = cntScore; } else notDone = false; } while (notDone == true); return foundIt; } 19. Which aspects of the fragment (of those listed below) violate good style standards (as defined in this course)? I. having the { after do (on the same line)—the { should be on its own line directly underneath do II. The constants –9, -99, 0 and 100 should have been named, and the names should have been used in the fragment III. Using notDone == true as the test for the loop—there is a cleaner expression that can be used IV. The user is not told the sentinel value A. I and II only B. III and IV only C. I, II and III only D. II, III and IV only E. I through IV
- Assistant
C. I, II and III only