This site requires JavaScript, please enable it in your browser!
Greenfoot back
rockaal
rockaal wrote ...

2019/4/6

Need help (Beginner)

rockaal rockaal

2019/4/6

#
Can we make some same object but every object had certain condition ? for example i have bee and fly, the bee will eat fly after bee eat fly the fly will respawn but with its own speed and every fly spawned it will have own speed.
Super_Hippo Super_Hippo

2019/4/6

#
If you have a field like this
private int speed;
then every object of this class will have its own variable speed. If an object adjusts its speed, then only this object will be affected, no other objects of the same class. On the other hand, if you use the static keyword
private static int speed;
then every object of the class will share this variable with each other. So in your case, you should be able to get the results you want without using a static speed variable.
You need to login to post a reply.