Java Questions 21 - 30  «Prev  Next»

Java Questions 23

  1. Reference variables can be declared as
    Answer:
    1. static
    2. instance variables
    3. method parameters
    4. local variables
  2. When can instance variables be initialized?
    Answer:
    Instance variables can only be initialized when the class is instantiated, or they can be assigned a null value.
  3. What are instance variables?
    Answer:
    Instance variables are the fields that belong to each unique object.
  4. What are local variables?
    Answer:
    Local variables are variables declared within a method or block. A local variable is destroyed when the method has completed.
  5. Where are local variables maintained?
    Answer:
    Local variables are always on the stack.

  6. What is the life of a local variable?
    Answer:
    The life of a local variable is only within the scope of the method.
  7. What is the difference between objects and local variables?
    Answer:
    Objects are placed on the heap and loal variables are placed on the stack.
  8. The only modifier that can be placed in front of a local variable is "final"

    Answer:
  9. Do local variables receive default values?
    Answer:
    No. Local variables do not receive default values.
  10. What does the keyword "this" refer to ?
    Answer:
    The keyword "this" always refers to the object currently running.