I’m just beginning to learn Java and I have been very frustrated about learning Java’s scope rules. You see I wish to create a Method without the use of arguments/parameters.
In JavaScript, I can do this with ease using functions:
/** Function to increase 2 vars.
/** **/
function modifyNow(){
a++;
b++;
} // END
var a = 5;
var b = 10;
modifyNow();
// By this part, a and b would be 6 and 11, respectively.
Now this is saving me a lot time and simple since whenever the function is called, var a and b, already exist.
So, is there a way to do this in Java without having arguments like how I do it in JavaScript? Or is there another way around this?
Thank you, appreciate the help… ^^
You need to use what are called
membervariables, they are tied to aninstanceof your class.Everytime you do a
new MyClass()you will get a new independentinstanceofMyClassthat is different from every otherinstance.As you are learning JavaScript is not related to Java in anyway. It is a terrible travesty that they picked that name for marketing reasons.