![]() |
|
|||||||
| Final Fantasy | Final Fantasy Forums | Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 1001001011 Come to this forum to get technical help, or just discuss technology as a whole; computers, electronics, phones, and other accessories that make us drool. |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|
#1 (permalink) |
|
La di da
|
For some odd reason, I took a computer programming course back in fall (I still don't understand why I did that since computers are more foreign to me than aliens) sadly the course exam is coming up, and there are quite a bit of information that I've forgotten...
Anyways, for those of you who remotely understand computer programming and Java, I'd be most grateful if you can tell me what the "static" key word is functioned as in a set of code.
__________________
![]() "When you're dreaming with a broken heart, waking up is the hardest part..." |
|
|
|
|
|
#2 (permalink) |
|
BOOM HEADSHOT!
Join Date: Jan 2007
Age: 22
Posts: 299
Rep Power: 4
![]() |
A Static bit of information (i.e. a method / function or a field / variable / whatever) is basically accessible without having an instance of the class you've put it in. You can use it to put in data and/or methods that are accessible from anywhere, for example a counter that keeps track of the amount of instances of a class
Code:
class Pete {
private int aNumber;
static int instances;
public Pete( int num ) {
aNumber = num;
Pete. instances++;
}
}
[code] class Pete { static void Reset() { Pete.instances = 0; } } Which is basically it. As far as I know, you can't declare variables or methods outside of a class (contrary to more old-school languages like C and/or PHP), so the Static keyword is the way to still be able to do stuff like that. Look here for some more detailed information (or if the above is still too complex, ), for great justice. |
|
|
|
|
|
#3 (permalink) |
|
La di da
|
Ah I see, thank you very much.
Since the teacher is new and rather incompetent I've resolved to asking people and reading the textbook (*shudders*), and I must say your explanation is more straightforwards than the book's sad excuse for a definition...
__________________
![]() "When you're dreaming with a broken heart, waking up is the hardest part..." |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|