How to Access and Modify Variables from Different Classes in Java -


this question may it's been asked million times, , that's because has. unfortunately, , maybe fault don't think so, has not been thoroughly , accurately answered. have been looking while answer question , come across many ambiguities , looking actual answer. in research have seen following: "use static variables, never use static variables, use getter , setter, getter's , setter's evil, global variables not exist in java, make public variable, public variables should not used" , more. i'm wanting have variable has value can accessed , changed multiple class , these multiple classes can see changes made variables value. how possible , best way of doing it?

there heap of different ways, , depends on how secure want variable be. tend use getters , setters because it's easier track method calls change of variable.

if it's class sole purpose hold values in variables might want use direct variable calls, if values in more functional class use getters , setters.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -