Content
5.3
Attributes
(Class and Instance)
5.3.4
Class
data and static variables
Variables that are associated with a
class and are shared by all objects of the class are known as class or
static variables. A given class will only have one copy of each of its
class variables. The class variables exist even if no objects of the
class have been created. If the value of the class variable is
changed, then the new value is available to all objects. This is quite
different from instance variables where changing a value for one
object does not affect the values in other objects. The keyword
static
is used as a qualifier to define a class variable.
The sample code shown in the Figure for the
CreditCardUser and CreditCardAccount classes illustrates the use of
the keyword
static
and the impact of shared data on object data.
Wyszukiwarka
Podobne podstrony:
contentcontentcontentcontentcontentcontentcontentcontentcontentfunction domnode get contentcontentcontentcontentcontentcontentcontentwięcej podobnych podstron