java - Changing a static variable with a static method -


this question has answer here:

i'm trying change private static variable via static method , bluej says can't because variable i'm trying change (which declared static) non-static:

public class playerinfo {     private static string name = ""; //stores name of 'player'     public static void setname(string name) {         this.name = name;     } } 

the variable called name , method called setname. know can this:

playerinfo.name = (insert variable here) 

i don't above because wish have name variable in playerinfo declared private not meddled other classes easily.

there no this inside static method.

your best bet rename parameter of method:

public class playerinfo {     private static string name = ""; //stores name of 'player'     public static void setname(string newname) {         name = newname;     } } 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -