{For java learners} Different kinds of Variables {For java learners} | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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; } }

15th Mar 2017, 2:36 AM
Ram chandra Giri
Ram chandra Giri - avatar
5 Answers
+ 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
15th Mar 2017, 1:13 PM
Katarzyna Jordan
Katarzyna Jordan - avatar
+ 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.
15th Mar 2017, 11:47 AM
Ram chandra Giri
Ram chandra Giri - avatar
+ 6
You are awesome @Ram Sir
15th Mar 2017, 3:14 AM
Siddharth Saraf
+ 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; }
15th Mar 2017, 11:29 AM
Katarzyna Jordan
Katarzyna Jordan - avatar
+ 1
maan these clever ppl... i dont understand a word ur saying. prob cuz im 13
21st Mar 2017, 9:02 PM
Krisztian Gyurka
Krisztian Gyurka - avatar