static has got nothing to do with the visibility/scope of fields or methods. Its just that these dont require an instance of the class and can be accessed as ClassName.fieldName or ClassName.methodName. The warnings you see are might be due to the fact that the method doesnt use any of the instance fields and might be not dependent on availability of any instance. But I think you might have seen these warnings in the IDE?
And public is used to define the fields/methods visibility. Public is the most liberal visibility and the fields/methods declared can be accessed anywhere in the code. Then you have protected, private and the default which is pacakge scope.
'static' means the variable or method is defined for the class itself; this is in contrast to an instance variable, which is defined for objects that are instances of the class.
Therefore, if you have a static variable, then no matter how many objects you have that are instances of that class, you still only have one variable by that name. You have a different set of instance variables for each object, but only one of each static variable.
If I have a Car class, and it has a static int variable carCount, and I instantiate 100 Car objects, I still have only one carCount variable, and I could keep a count of each car I instantiate there if I want.
A static method can be invoked without using an instance of the object. Let's say I have a method that returns the count of cars, using the static variable carCount, called getCarCount(). It would not make as much sense to define this on an instance of Car; it is not related to any one Car, but to all the Car objects. So getCarCount() could be a static method, and could be invoked with "Car.getCarCount();". If you instantiate Car and use the instance variable familyCar to hold a reference to it, then using familyCar.getCarCount() will give you the message you speak of, since you are invoking a static variable but using an instance to do it.
'public' just means that any class can access the variable or method. this is in contrast to 'private' that limits access to code within the class, and a couple of others that limit it other ways.
Is that what you were looking for?
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop