| Author |
Instance Variables
|
Stephen Foy
Ranch Hand
Joined: Oct 17, 2005
Posts: 143
|
|
|
How do you create them in java?
|
Stephen Foy - Microsoft Application Development Consultant
|
 |
Ko Wey
Ranch Hand
Joined: Sep 08, 2003
Posts: 67
|
|
Read the stuff on this page: http://java.sun.com/docs/books/tutorial/java/javaOO/classvars.html
|
 |
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
|
|
Whenever you declare a variable without the keyword "static," you have an instance variable. This is all explained in Ko's link above, but let me try my own brief explanation... You define Java classes, which (usually) include fields (variables) and methods (functions). The class can serve as a "blueprint" for creating an object, also known as an "instance" of the class (which you create using the keyword "new"). By default, fields and methods are "instance" members, meaning that an instance must be created in order for these fields and methods to be used. In contrast, fields and methods can be declared "static," in which case they are not associated with any particular instance, but are instead simply associated with the class itself. To use static fields and methods, no instance needs to be created -- they can be called directly from the class. [ November 12, 2005: Message edited by: marc weber ]
|
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
|
 |
armeen golden
Greenhorn
Joined: Oct 02, 2005
Posts: 8
|
|
|
so can we say that instance varialbes are associated with a particular instance and not with the entire class?
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16487
|
|
|
Yes, that is correct.
|
 |
 |
|
|
subject: Instance Variables
|
|
|