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
Post a Comment