By using this site, you agree to our Privacy Policy and our Terms of Use. Close
vlad321 said:
JaggedSac said:

Also, don't use Double unless it is necessary, instead use double. double is a primitive, and Double is a wrapper object for a double primitive.

And vlad321, it has everything to do with scope, he was trying to access the non-static x and y variables from a static context.

Scottie, it would be helpful if you would just post all of your code.  And just for clarification, what does Body have that you are extending?  Bounding box, helper methods, etc?

 

Static is not scope. It has nothign to do with restrictions from where a variable is visible.

Static variables are bound to a class and not an object instance.  In this compilation error, it is most likely referring to the SpaceShip.x and SpaceShip.y.  SpaceShip is the name of the class and it is expecting there to be x and y static variables in the class.  But without more code to look at, it is hard to tell.  Here is most likely what he did.

 

public class Bullet extends Body{

public Double x;

public Double y;

public Double xVelocity = x - SpaceShip.x;

public Double yVelocity = y - SpaceShip.y;

...

...

In which case SpaceShip does not have static variables with this name.

Java does not have a global scope but static variables are as close as it gets.  There is only one instance of each static variable per ClassLoader(A JVM can have more than one class loader).  But you are correct in that static does not define visibility.