Java Questions 41 - 50  «Prev  Next»

Shadow Java Variables and Arrays(Questions)

  1. What does shadowing involve?
    Answer:
    Shadowing involves re-declaring a variable that has already been declared somewhere else.
  2. What type of data types can arrays hold?
    Answer:

    Arrays can hold either primitives or object references, but the array itself will always be an object on the heap.
  3. Where is an array stored?
    Answer:

    Even if the array is declared to hold primitive elements, the array itself will always be an object on the heap.
  4. How would you declare 1)an array of Primitives versus 2) an array of Object References?
    Answer:
    This first example is an array of primitives
    a) int[] key; 	
    

    This second example is an array of Object References.
    b) Thread[] threads;
    
  5. Is it legal to include the size of the array in your declaration?
    Answer:
    No. It is not legal to include the size of the array in the declaration.
  6. What is true about space allocation and Java arrays?
    Answer: The JVM does not allocate space until you actually instantiate the array object.
  7. Where do all objects reside?
    Answer:
    All objects live on the heap. Constructing an array means creating the array object on the heap.
  8. What are two ways of declaring arrays?
    Answer:|
    int[] testScores; 
    testScores = new int[4];
    

    How can you declare and construct an array in one statement?
    int [] testScores = new int[4];
    
  9. What does the following declaration do?
    Thread [] threads = new Thread[5];
    

    Answer:
    1. The preceding code produces just one object (the array assigned to the reference variable named threads)
    2. The single object referenced by threads holds 5 Thread reference variables
  10. Which 3 words are used interchangeably to indicate "an object is built on the heap"?
    Answer:
    1. Construct
    2. Create
    3. Instantiate