We declare local Variables when we want some variables for local use only and which we don’t want later. If we need Variables only inside 1 method then don’t declare them as Global Variables. Local Variables store value for less time, I mean to say that when execution of method finish then local Variables lose their value and become available for another method. Using Local Variables manage memory allocation in JVM. That’s why avoid declaring Variables as Global. Declare Variables as Global when its requested in multiple methods.
We declare Global Variables when we need same value inside multiple methods and inner classes. Global Variables work as communication medium between multiple methods.
For example, if we want to transfer value from 1 method to another method then we can pass value to Global Variables and get value from that Global Variables inside another method.
Quick Links
Legal Stuff
Social Media