I am confused about the variables. Java has 3 different variables:
Local variables are declared and used in the class. But what is the difference between class and instance variables.
Thanks for your time.
Hi there mew
Originally Posted by mew
ok, lets take this one at a time.
Local variables are variables that are initialised and used by methods of a class. Their lifetime begins when a method is called or is running, and ends when the method has finished running.
Class variables are variables that belong to the class, are declared once and shared by the entire class as a whole. These variables are not owned by a particular instance (object) of the class/
Instance variables however are owned by objects or instances of the class and makes-up the data portion of the objects. Each object (instance) of the class will have its own separate copy of the instance variables.
Hope this helps...
Thanks definewebsites for the details.
Your explanation cleared my confusions.
Glad I could help...
All the best...