| Author |
difference between instance variable and class variable
|
Divya Gehlot
Ranch Hand
Joined: Sep 10, 2006
Posts: 238
|
|
Hi, Can Any one explain me difference between instance variable and class variable.As i got confused with those. Thanks in advance.
|
SCJP1.5(81%)<br />SCDJWS(94%)<br />next mission SCEA(but need to wait or that)
|
 |
Ameen khan
Ranch Hand
Joined: Jun 10, 2007
Posts: 52
|
|
[ August 07, 2007: Message edited by: Ameen khan ]
|
SCJP 5.0<br />Next-> I Don't Know
|
 |
Mani Ram
Ranch Hand
Joined: Mar 11, 2002
Posts: 1140
|
|
Originally posted by Ameen khan: Class variables = instance variables + static variables
When you create different instances of a class, each instance will have it's own copy of the (instance) variables defined in the class. Modifying an instance variable of one class won't affect the instance variable of another class. When you define a variable as static, it becomes a class variable. In this case only one copy of the variable is made and all the instances will share this single copy. If you make a change to this variable, it will reflect everywhere (i.e. in all instances).
|
Mani
Quaerendo Invenietis
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12929
|
|
See this: Understanding Instance and Class Members Instance variable: For every instace that you create of a class, there is a separate copy of the variable - each object has its own copy of the variable. Class variable: There is one variable which is shared by all the instances of the class - there's only one variable which is shared by all the objects. Class variables are member variables that have the static modifier. Instance variables are member variables that do not have the static modifier.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
srinivas sridaragaddi
Ranch Hand
Joined: Jul 24, 2007
Posts: 225
|
|
hi i found the difference, its not very detailed but basic difference is given and the link is http://www.sap-img.com/java/difference-of-class-variable-and-instance-variable.htm
|
SCJP 5.0<br /> <br />"Skills are started with learning and mastered with improvement. Nothing is hereditary except death" BUDDHA...
|
 |
srinivas sridaragaddi
Ranch Hand
Joined: Jul 24, 2007
Posts: 225
|
|
hi i found the difference, its not very detailed but basic difference is given and the link is http://www.sap-img.com/java/difference-of-class-variable-and-instance-variable.htm
|
 |
 |
|
|
subject: difference between instance variable and class variable
|
|
|