Local Variable and Instance Variable in JAVA

Local Variables 

  1. Variables which are declared within a Method are referred as a Local variable.
  2. These variable are allocated memory in the stack.
  3. These variable are allocated memory once the control enters the Method.
  4. The memory of these variables are deallocated once the control leaves the method.

local-variables.gif

Instance Variable

  1. Variables which are declared within the class are referred to as Instance variables.
  2. They are allocated memory only when an object is created.
  3. The memory will be allocated in the Heap.
  4. Deallocation of memory cannot be predicted as it is deallocated by Garbage Collector.instance variable.png

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

Powered by WordPress.com.

Up ↑

%d bloggers like this: