Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

Share this Page URL

B. Introduction to Classes, Objects, Met... > B.3. Declaring a Method with a Param... - Pg. 526

526 Appendix B Introduction to Classes, Objects, Methods and Strings Any class can contain a main method. The JVM invokes the main method only in the class used to execute the application. If an application has multiple classes that contain main , the one that's invoked is the one in the class named in the java command. Compiling an Application with Multiple Classes You must compile the classes in Fig. B.1 and Fig. B.2 before you can execute the applica- tion. First, change to the directory that contains the application's source-code files. Next, type the command javac to compile both classes at once. If the directory containing the application includes only this application's files, you can compile all the classes in the directory with the command javac *.java The asterisk ( * ) in *.java indicates that all files in the current directory that end with the file-name extension " .java " should be compiled. B.3 Declaring a Method with a Parameter In our car analogy from Section 1.10, we discussed the fact that pressing a car's gas pedal