Classes normally have methods that manipulate the attributes that belong to object instantiations of the class.
Attributes are realized in the form of variables inside a class declaration. These attributes(variables) are declared inside the class declaration but outside the bodies of the class's methods.
**When each object of a class maintains its own copy of an attribute, the field that represents the attribute is also known as an "instance variable" - each object (instance) of the class has a separate instance of the variable in memory.
Reference: "Java How to Program, by Deitel & Deitel"
HL ; computer programming ; all languages
Saturday, November 20, 2010
Java - Instance Variables
Prior to this point, all the the variables we used we declared in an application's main method.
When a variable is declared in the body of a method, it is categorized as a "local variable', and that variable can only be used inside that method.
When the particular method terminates (right after it finishes execution), all values of its local variables terminate with it.
**On the other hand, objects can have attributes that it carries with it, regardless of whether one of its methods are in execution or have finished execution or not.
**These attributes exist before a method is called (as soon as an instance of the object is instantiated), and continues to exist independent of the execution or completion of any of its methods.
When a variable is declared in the body of a method, it is categorized as a "local variable', and that variable can only be used inside that method.
When the particular method terminates (right after it finishes execution), all values of its local variables terminate with it.
**On the other hand, objects can have attributes that it carries with it, regardless of whether one of its methods are in execution or have finished execution or not.
**These attributes exist before a method is called (as soon as an instance of the object is instantiated), and continues to exist independent of the execution or completion of any of its methods.
Subscribe to:
Posts (Atom)