static keyword

Hello.
I am new to java. I thought you only put one static statement in the code, "public static void main(String[] args)"

But this code has more than one static statement.

What is the difference between the first 2 static statements & the ""public static void main(String[] args)" statement? Why have both? Why not put the 1st two static statements under the public static... statement? Is this example trying to show me different ways of using static? Thanks In Advance.

Im also fairly new but here is what I have to say. I believe this is a fairly accurate explanation, although, I am sure a more experienced programmer will explain it better.

Static allows a method to be used by multiple objects.

Lets say you create a static method called Print, which really just allows you to use the words print("some item"); instead of System.out.println("blah"); in order for the static item to be used anywhere it needs to be static.
To create the print method you would create a class called Print which has all the overloaded definitions of print. Normally if you wanted to use a method from a class, you would have to create an instance of that class:

Java Code:

Print x = new Print();

static allows you to use the method without an instance of the object.

The static keyword is a bit challenging for me to explain, I understand it though.

When you are dealing with multiple classes and polymorphism, I can see where static really gets useful.

Have you messed with multiple classes and creating objects yet?

If not that's ok. You can practice LOTS of stuff without understanding static. Once you start learning more basics you go back to an area you were having trouble and for some reason it makes more sense.

static keyword (ahhhhh... i get it)

It's no public static statement but a method-declaration (of the main method).
The first two static declarations (and initializations) are global statics. They have (if properly declared private which they are not) global scope in the class (now in the package). Maybe console needs applicationwide scope, than make it public. Other variables, like firstnum, have method-scope. There is no limit on the number of statics as you suggested, but most variables are bound to instances of a class, not to the Class as such, like others explained already.
There are properties of cats in general (mean and furry) and of a particular cat (sweet).

there is two variable one is static inGarage and one public thisType. Notice how one counts up an inGarage keeps going up while thisType is doesn't. This is because thisType is not static and has a separate thisType varaible for each object. There is only one static variable inGarage that they all share.

I used polymorphism to extend Vehicle class, that is what all the extra classes are for... if you do not understand this topic, do not worry, just worry about the static and public variables at least in this example :)

@AcousticBruce:
At first I thought your program was wrong (I looked at the code and thought, "this isn't working", only then I saw that you instructed OP to change static for public). Now I think it's confusing because the variable is called "carsInGarage" in stead of "vehiclesOfThisKindInGarage".
@OP:
public static variables have a special role because once initialized they are seen everywhere and always in your program ("always" means: you don't first have to make a new class instance to access the variable).
There are also static methods. They are often little tool-methods found in libraryclasses and just do something irrespective of the containing class, like in the old days before Object Oriented Programming.

@AcousticBruce:
At first I thought your program was wrong (I looked at the code and thought, "this isn't working", only then I saw that you instructed OP to change static for public). Now I think it's confusing because the variable is called "carsInGarage" in stead of "vehiclesOfThisKindInGarage".
...

I can see where you are coming from. The main idea was to just count the new Vehicles. When it is static it does just that.
i just edited the code so it makes more sense... please let me know if this is confusing, that is the last thing I wanted to do.

Hello AcousticBruce
I'm very confused, but not about your new code, that looks good.
No offence, but I'm confused because your code in the thread upon which I reacted has also changed in the new version. That version had no subclasses and made new Vehicles. I keep rechecking. Have senior members the power to change history in the thread? I really not get it.

Correction, I made a mistake. I see that I too have the power to edit my contributions. (I'm rather new to forums.) But is it the right way to do? Should a thread not mirror the history of discussions, except gross (writing-)errors? No one now knows what I reacted on.
But maybe now I'm going to correct stupid embarrassing remarks I made in other threads ;>)

Last edited by Jodokus; 01-11-2011 at 07:21 PM.
Reason: tread to thread

Correction, I made a mistake. I see that I too have the power to edit my contributions. (I'm rather new to forums.) But is it the right way to do? Should a thread not mirror the history of discussions, except gross (writing-)errors? No one now knows what I reacted on.
But maybe now I'm going to correct stupid embarrassing remarks I made in other threads ;>)

Actually you are right. I like that philosophy. That makes perfect sense. I will from now on not go back and change my posts, because it can confuse and that is what new posts are for.