static concept : variable and method in class defination

Go4Expert Member
25Oct2010,10:40   #1
mocha's Avatar

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?
Mentor
27Oct2010,13:21   #2
xpi0t0s's Avatar
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.
Go4Expert Member
28Oct2010,13:27   #3
mocha's Avatar
great.I understand many things by your answer.
Thanks a lot.