Question:
What is static variable?
Answer:
A static variable is one that is not removed from memory after creation, even when it goes out of scope. The concept is very similar to that of a global variable, except that while a global variable is accessible from anywhere, a static variable is only accessible within certain parts of the program code.
The opposite of a static variable is an instance variable , which is a variable related to a single instance of a class.
Submitted by Amit Mathur Source: CoolInterview.com
value is the same for all instances of the class. static variable give u a vlaue sharedby all instances of a class, in other words,one valu per class instead of one value per instance. Source: CoolInterview.com
Answered by: Risikesh | Date: 9/21/2009
| Contact Risikesh
static variable is a class level variable, this variable will be initialized at the time class loads in the memory,it's having only one copy accross the objects of the class, if one object is modifying the value of the static variable then it will be visible for all objects of the class Source: CoolInterview.com
Answered by: Soumya Kundu | Date: 11/14/2009
| Contact Soumya Kundu
Static variable is the one which got memory only once when the class get initialized.
It is per class basis.not per object basis. Source: CoolInterview.com
Answered by: Bodya | Date: 3/1/2010
| Contact Bodya
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|