+ 2

What is the difference between a local variable and reference variable in java?

20th Aug 2019, 5:28 PM
Piyush Srivastava
Piyush Srivastava - avatar
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.
20th Aug 2019, 5:45 PM
voja
voja - avatar
+ 1
Ok thanks
20th Aug 2019, 5:50 PM
Piyush Srivastava
Piyush Srivastava - avatar
+ 1
every variables in java are local, if in variable is stored object it is referece to that object.
20th Aug 2019, 6:17 PM
zemiak