Does Java keep only one copy of a method in memory regardless of whether the method is static or non-static? Or are methods like variables--static methods: only one copy; non-static methods: one copy per object.
Im gonna take a stab at answering this question from what I think.... I might well be wrong =D With a static you would only have one copy. With a non static each method is associated with a specific object, and since each object is unique with respect to its state etc, then the methods associated with that object are also unique. Thus there is a copy of each method for each non-static object.
Hi, While in the topic i was wondering what happens to a variable declared as final ? Does that also behave like instance variables or like static variables ? And what is the difference between Static and final variables ? ------------------
A final variable can never be changed. int i = 3; final int varFinal = i ; varFinal = 2 ; // will not compile varFinal will forever after be 3. You have finalized it. A final variable can be defined as a class variable or as a local variable or as an instance variable. On the other hand, a static variable is a class variable. int i = 3; static int varStatic = i ; varStatic = 2; // this is valid There is only one reference (in this case "varStatic") but the value can be changed, and when it is, it is changed for every time "var" is referenced.
JavaBeginnersFaq "Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.