+ 2
What is the difference between a local variable and reference variable in java?
3 Réponses
+ 8
Variables can be:
static
instance or
local
and based on their type, they can be:
primitive or
reference
So a variable can be local and reference at the same time.
Local variable is defined inside a method, block or inside for statement.
Variables of a reference type hold a reference to some object.
Example:
class Program {
public static void main (String [] args) {
Program p;
}
}
Here p is a reference and a local variable.
+ 1
Ok thanks
+ 1
every variables in java are local, if in variable is stored object it is referece to that object.