In Java why we write public static void main(String args[])
why not main()?
Answer Posted / priyanka
DECRIPTION ABOUT PUBLIC:
The main method should be acceseible to every function
which is inside the package and outside the package. and it
is possible only if main method is declared as public
DECRIPTION ABOUT STATIC:
Static is a storage class. static allocates space for
its data and it is first step done after compilation. In
java main method is coded inside a class.. but compiler
need to call the main method first as it is one of the
protocol in ANSIC..
A method in the class without creating an instance can
be called only if the method is static.. so main method
should be static
DECRIPTION ABOUT VOID:
As main method returns nothing or empty main is declared
as void
DECRIPTION ABOUT STRING(ARGS[]):
In java every input is considered as string. even the
input is of integer type it is taken as string. so main
takes arguments of type string.
| Is This Answer Correct ? | 9 Yes | 0 No |
Post New Answer View All Answers
What is a package in java? List down various advantages of packages.
Are arrays immutable in java?
Give the hierarchy of inputstream and outputstream classes.
Difference between throw and throws?
what is collatration?
What is a singleton class in Java?
What is the final field modifier?
Is 0 an irrational number?
What is static block?
How many types of java are there?
How do you convert string to int in java?
What are predicates in java 8?
Which eclipse is best for java?
Does constructor return any value?
What are the advantages of autoboxing?