Java Questions 23
- Reference variables can be declared as
Answer:
- static
- instance variables
- method parameters
- local variables
- 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.
- What are instance variables?
Answer:
Instance variables are the fields that belong to each unique object.
- 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.
- Where are local variables maintained?
Answer:
Local variables are always on the stack.
-
What is the life of a local variable?
Answer:
The life of a local variable is only within the scope of the method.
- What is the difference between objects and local variables?
Answer:
Objects are placed on the heap and loal variables are placed on the stack.
- The only modifier that can be placed in front of a local variable is "final"
Answer:
- Do local variables receive default values?
Answer:
No. Local variables do not receive default values.
- What does the keyword "this" refer to ?
Answer:
The keyword "this" always refers to the object currently running.