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
2 Antworten
0
so the number of balls in each CONTAINER can only be one if CONTAINER is non static.am i correct
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