In the previous post, talked about how many elements of a java class & local variable. Now we learn about Instance variable.
2. Instance Variable
- Declaration:- The variables which are declared inside the class but outside of the method that are called instance variable.
- Scope:- The variable can access inside the class. All methods, constructors and blocks of the class also able to access the variables.
- Memory Allocation:- Memory is allocated in object creation time. Memory released when object is destroyed.
- Stored Memory:- Heap is a memory place where the objects, and its instance variable are stored.
3. Static Variable
- Declaration:- The variables which are declared inside the class and outside of the method with static modifier are called static variable.
- Memory Allocation:- When .class file is loaded the memory allocated.
- Scope:- The static variable can access within the class. Access by class name.
- Stored Area:- The variable stored in non-heap memory.
To set up java environment visit here.
Next post is coming soon.......