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

What is the difference between math floor and math round?

505


What is boolean law?

520


Is main a keyword in java?

540


What is data type in java?

487


What is the final access modifier in java?

617






Give us a program to check for parenthesis matching using stack.

562


How do you check if a number is a perfect square?

516


What do you mean by of string::valueof expression in java 8?

543


Can there be an abstract method without an abstract class?

541


What is difference overloading and overriding?

579


Difference between default and protected access specifiers?

505


Why set is used in java?

573


Can a lock be acquired on a class in java programming?

536


What is function declaration?

532


What is the integer of 16?

539