View Single Post
Old 26-01-2010, 06:16 AM   #1
javaguru
Member
 
javaguru's Avatar
 
Join Date: Dec 2009
Posts: 50
Rep Power: 15
javaguru is on a distinguished road
Default main method in Java

Q - Briefly explain the reason that the main method in a Java application is declared public.

A - The keyword public indicates that the method can be called by any object.

Q - Explain the reason that the main method in a Java application must be declared static.

A - The keyword static indicates that the method is a class method which can be called without the requirement to instantiate an object of the class. This is used by the Java interpreter to launch the program by invoking the main method of the class identified in the command to start the program.

Q - Describe the purpose of the keyword void when used as the return type for the main method.

A - The void keyword when used as the return type for any Java methods indicates that the method does not return anything.

Q - What is the use of args[]?

A - The formal parameter args is an array of type String, which contains arguments entered at the command line. Note that the args parameter must be specified whether or not the user is required to enter a command-line argument and whether or not the code in the program actually makes use of the argument.
javaguru is offline   Reply With Quote