static variable , public static, and private static [Resolved]

Posted by Mcadeepuraj under Interview Questions on 3/7/2011 | Points: 10 | Views : 3707 | Status : [Member] | Replies : 2
what is static variable, what is private static and public static.

Deepak Kumar


Responses

Posted by: Gsolvers on: 3/7/2011 [Member] Starter | Points: 50

Up
0
Down

Resolved
static variables are those variables whose values are shared among various instance of an class. For e.g. if you have a static variable "x" in class "A" and you create two instances of A i.e. a1 and a2. In that case a1 and a2 will share the common variable. This means if a2 changes the value of x than this will be changed for a1 as well.

Class A
{
static int x;
}

A a1=new A();
A a2=new A();
a1.x=10;

then a2.x will also become 10.

Hope the above helps. Also Private and public are having the same global meaning. This means private static are accessible within the class but public are accessed outside the class as well.




Best Regards,

VG
www.TeacherJi.com

Mcadeepuraj, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 3/7/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Check these links

http://www.eggheadcafe.com/articles/20020206.asp

http://msdn.microsoft.com/en-us/library/aa691162(v=vs.71).aspx

Thanks
Karthik
www.f5Debug.net

Mcadeepuraj, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response