1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

static concept : variable and method in class defination

Discussion in 'C' started by mocha, Oct 25, 2010.

  1. mocha

    mocha New 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?
  2. xpi0t0s

    xpi0t0s 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.
  3. mocha

    mocha New Member

    great.I understand many things by your answer.
    Thanks a lot.

Share This Page