Do I want to access the method without an instance of the class?
If you answered yes, you probably want a static method.
private static variables can be used to share data across instances of that class, i.e. if you have:
public class Car
{
private static int wheelsNum;
private String company;
private String color;
...
...
}
Then if you change wheelNum
to be 2, then all cars will have 2 wheels.
For example, consider this piece of code:
Car car1 = new Car();
Car car2 = new Car();
car1.setColor("Yellow");
car2.setColor("Blue");
car1.setWheelsNum(4);
car2.setWheelsNum(2);
Then both cars will have 2 wheels, although I "didn't" mean to change the wheels number of the first car. But, as you can tell, the cars have different colors.
public static
variables used without making instance of the class, wheras private static
variables are not.
When you need to use a variable in a static function, you can only use static variables, so making it private to not access them from other classes.
Static methods can't access non-static methods (and the same for variables).