0

Static java beginner question(am i understanding correctly?)

we treat values as number of balls and human will throw balls into the CONTAINER variable.since CONTAINER variable is static.thus all human share this one and only container.when human object is created,number of balls is incremented as every human objects created will throw the ball inside this one and only CONTAINER.if CONTAINER is not static,for every one human created,one CONTAINER will be created too.so if there is 10 human objects there are 10 CONTAINER.https://code.sololearn.com/cnFeh6394QtA/?ref=app

1st Dec 2017, 7:48 PM
oyl
2 odpowiedzi
0
so the number of balls in each CONTAINER can only be one if CONTAINER is non static.am i correct
1st Dec 2017, 7:57 PM
oyl
0
If CONTAINER is non-static then it's field of class and each object have own "version" of the field. If CONTAINER is static then it's one variable for all objects. I think you understand correctly. But if CONTAINER is non-static you can't use Human.CONTAINER, because in this case you need object from Human class to use non-static variable
1st Dec 2017, 9:39 PM
Pyzhyk Anton
Pyzhyk Anton - avatar