Java Questions 41 - 50  «Prev  Next»

String Reference Variable(Java Questions)

  1. What happens when you use a String reference variable to modify a String?
    Answer:
    1. A new string is created ( or a matching String is found in the String pool), leaving the original String object untouched
    2. The reference used to modify the String (or rather make a new String by modifying a copy of the original) is then assigned the brand new String object .
  2. What does a eference variable hold?
    Answer: A reference variable holds bits that represent a way to get to a specific object in memory (on the heap).
  3. What happens when you pass a reference variable?
    Answer:
    When you pass a reference variable, you are passing a copy of the bits representing how to get to a specific object.
  4. What do both the caller and called methods have identical copies of?
    Answer: Both the caller and called method will have identical copies of the reference.
    1) Caller, 2) Caller method
  5. What do the 1) caller and 2) called method both refer to on the heap?
    Answer:
    The 1) caller 2) called method will refer to the same exact object on the heap.
  6. It does not matter whether you are passing 1) primitive or 2) reference variables, you are always passing a copy of the bits in the variable.
    Answer:
  7. If you are passing an object reference variable, you are passing a copy of the bits representing the reference to an object.
    Answer:
  8. What is the method capable of when you "Pass-By-value"?
    Answer:
    The called method can not change the caller's variable. When you implement "Pass-By-value", the called method can not change the caller's variable.
  9. What is a method capable of when you "Pass By Reference: For object reference variables the called method can change the object the variable referred to.
    Answer:
    Pass By Reference: For object reference variables the called method can change the object the variable referred to .
  10. Can the called method reassign the caller's original reference variable and make it refer to a different object or null?
    Answer:
    For object references, the called method cannot reassign the caller's original reference variable and make it refer to a different object, or null.