static concept : variable and method in class defination

mocha's Avatar, Join Date: Oct 2010
Go4Expert Member

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?
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
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.
0
mocha's Avatar, Join Date: Oct 2010
Go4Expert Member
great.I understand many things by your answer.
Thanks a lot.