+ 32
{For java learners} Different kinds of Variables {For java learners}
Somebody could explain it, class Point { static int numPoints; // numPoints is a class variable int x, y; // x and y are instance variables int[] w = new int[10]; // w[0] is an array component int setX(int x) { // x is a method parameter int oldx = this.x; // oldx is a local variable this.x = x; return oldx; } }
5 odpowiedzi
+ 2
local variable oldx is using and existing only inside method setX. more here: http://javabeginnerstutorial.com/core-java-tutorial/local-variable-in-java/
intance variables (fields) are used by Objects to store their states. It's existing inside our class and can be used by all class' methods. more here: http://javabeginnerstutorial.com/core-java-tutorial/instance-variable-in-java/
class variable: http://javabeginnerstutorial.com/core-java-tutorial/java-static-keyword/
i hope it helps
+ 25
@Katarzyna thanks, but that code was example to demonstrate different types of variable that are in java. And I said somebody could explain, about local variable, class variable, instance variable.
Again thank you for taking your time.
+ 6
You are awesome @Ram Sir
+ 1
@Ram chandra Giri, i have tested your code and i think i know why it doesn't work. your method should look like this:
static int setX(int x){
return x;
}
+ 1
maan these clever ppl... i dont understand a word ur saying. prob cuz im 13