Heap Memory And References

5 Questions | Total Attempts: 278

SettingsSettingsSettings
Heap Memory And References

This is a "friendly quiz" with some multiple choice questions about heap memory, references, NullPointerExceptions, etc. If you choose an incorrect answer you have the option to view the correct answer. Also, you can hit your browser's "back" button to go back to the previous page and retake the question (this seems to work for all the questions except the last one).


Questions and Answers
  • 1. 
    Heap memory is used to
    • A. 

      Store the machine language code corresponding to the the program itself

    • B. 

      Store objects

    • C. 

      Store things that are no longer needed

  • 2. 
    From the following DrJava interactions what can you infer about p? > p [email protected]
    • A. 

      It is either null or pointing to a Widget

    • B. 

      Nothing - base 16 numbers freak me out

    • C. 

      It is pointing to a Widget stored at heap address 7ef48b2 (a base-16 number)

  • 3. 
    A NullPointerException causes a program to crash. It occurs when
    • A. 

      A program runs out of memory.

    • B. 

      The left operand of a dot operator is null.

    • C. 

      A reference variable is pointing to an object of the wrong type.

  • 4. 
    Choose the one true statement about the code below.                                        
    • A. 

      Method2() can not change the Counter pointed to by c because it's out of scope

    • B. 

      Method2() can change the Counter pointed to by c because it's known by all methods within the class.

    • C. 

      Method2() can change the Counter pointed to by c because method2() is given its heap address

  • 5. 
    Given the following code, choose the one true statement. public class A {     private B b;      }
    • A. 

      A "is a" B

    • B. 

      A "wannabe" B

    • C. 

      A "has a" B

Back to Top Back to top