Sunday 15 July 2012

java - Can non-static methods modify static variables -


I am wondering how a non-static method can modify a static example variable I know that the static methods only Other stable methods and stable variables can reach. However, is the other side true? Can non-static methods only use non-fixed variables? For example:

  public class sample class {private constant intra currentCount = 0; Public Sample Class () {currentCount ++; } Public zero growth calculation () {currentCount ++; }}   

This code has been compiled and I would like to know why in terms of stable access privaleges

I received it from

  • Example Example Directly the Impression Variable And access the instance methods.
  • Example methods can reach the square
  • Class methods can not directly access the impression variable or installation methods. Must use any object reference. In addition, class methods can not use this keyword because there is no instance to mention it.

    So the answer is yes, you can modify the static variable in a non-fixed way

No comments:

Post a Comment