Header Ads

Difference Between Local Variable And Instance Variable

As we go deep into java the question arises is what is the difference between local variable and instance variable? In this post I am trying to explain the difference between them

Local Variable Instance Variable
Local variable will not get any value bydefault Depending on the data type Instance variable will get default value.Like-bollean will get false
int will get 0 etc
The scope of local variable is very limited ..only inside the block (function) The scope is global
It is mandate to initialize the local variable to performa any action As by default it will get some value hence it is not mandate to initialize any value to the variable.
Mostly we will get compile time error if something goes wrong with Local variable Mostly we will get run time error if something goes wrong with Instance variable


Powered by Blogger.