Friday 21 October 2016

Types of Variables

Types of variables

  • To understand the type of variables we should aware the class, method and object concepts ( we ll learn in upcoming chapters ).
  • If you have any idea about class, method and object then you can go ahead.
Types of variables
● Instance variable
● Static variable
● Local variable
Based on location variables can are divided as below:
1. instance variable inside the class without static keyword
2. static variable     - inside the class with static keyword
3. local variable      - inside the method / block / constructor 
1. Instance Variables:
● Declared inside the class and outside the method/block/constructor  without static keyword
● Instance variables are used by objects to store their values.
● Separate copy of value is available for every variable in every object
● The scope of instance variable is scope of the object.
2. class/static variables
● Declared inside class and outside of method/block/constructor with static modifier.
● A single copy of static variable value is shared by all objects. 
● Scope of static variable is scope of the class.
3. Local variables
● Declared inside method/block/constructor and outside of class.
● These variables are defined and used just for instant usage.
● Local variables no longer exist after the method has returned.
 Parameters or Arguments: 
● These are variables passed into a method signature.
● These are not attached to modifiers (i.e. publicprivate,protected  or static) and they can be used everywhere in the method.
Thanks for your time.
-Nireekshan