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

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 part of its objects is called static. A static method is part of the class file, but is never part of an object. In addition to a static main() a class file can have other static methods, and can have static variables.

Sometimes the processing you want in the static main() method can get complicated. In keeping with the ideas of modularity, you would like to build the method out of smaller methods. These smaller methods are part of the class file (not of an object) and so must be declared static.

Also, sometimes the static methods access static data that is associated with the class (not part of any object.)

You can think of a class and its static methods as like an object, except there can only be 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 be the same as with the instance methods of the previous chapters?


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