Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   static concept : variable and method in class defination (http://www.go4expert.com/forums/static-concept-variable-method-class-t23660/)

mocha 25Oct2010 10:40

static concept : variable and method in class defination
 

hello every body ,
what is the answer for thees questions ?
When the keyword static is used on variable in a class definition, can the variable be altered in a non static method? Why or why not?

when the keyword static is used on a method in a class definition, can the method alter non-static variables in the class? why or why not?

xpi0t0s 27Oct2010 13:21

Re: static concept : variable and method in class defination
 
1. Yes, because the object exists when you invoke the non-static method, so there's no problem there.

2. No, because the object might not exist within the static function, so it isn't allowed to modify any non-static class members.

mocha 28Oct2010 13:27

Re: static concept : variable and method in class defination
 
great.I understand many things by your answer.
Thanks a lot.


All times are GMT +5.5. The time now is 15:07.