In Java why we write public static void main(String args[])
why not main()?

Answer Posted / ankur

in java we write public static void main(String args[])
instead of just main because:....

public.....The main method must be public because it is
call from outside the class. It is called by jvm.

static....The main method must be static because without
creating an instace jvm can call it. If the main method is
non static then it is must to create an instance of the
class.

void....Main method doesn't return anything therefore it is
void also.

(String args[])....It is used for receiving any arbitirary
number of arguments and save it in the array.

Is This Answer Correct ?    429 Yes 20 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why do we use return statement?

551


What is identifier in java?

566


What is flag in java?

541


What is singletonlist in java?

518


What is difference between array and vector?

545






Why hashcode is used in java?

505


What are the principle concepts of oops?

546


Explain the importance of finally over return statement?

616


What is the final class modifier?

567


What does the “static” keyword mean?

589


What is string variable?

580


Is a class an object?

586


Can you access non static variable in static context?

565


Is java code slower than native code?

569


is it possible to instantiate the math class?

535