go to previous page   go to home page   go to next page highlighting

Answer:

A static main() method is not part of an object. It is contained in the definition of a class.


Static

When the Java interpreter starts running a program, it looks for a static main() method in a class file. For example, when you enter

C:\JavaSource\>java Hello

the interpreter looks for main() in the file Hello.class

In Java, a characteristic of a class that is not included as part of its objects is called static. A static method is part of the class file, but is not part of an object of that class. In addition to a static main() a class file can have other static methods, and can have static variables.

Sometimes the processing you need in the static main() method is complicated. You would like to build that method out of smaller methods. These smaller methods can be part of the class file (not of an object) and so must be declared static.

Also, there can be static data that is associated with the class (not part of any object.)

You can think of a class and its static methods as somewhat like an object, except there is only one of them. Sometimes this is all you need.


QUESTION 2:

Can the static main() method invoke other static methods of the class?

Will parameter passing work the same as with the methods of previous chapters?


go to previous page   go to home page   go to next page