In Java why we write public static void main(String args[])
why not main()?
Answer Posted / shreya
main method is the starting point of our program
execution.and it calls first outside the program so that we
have to specified it public.public means access from
anywhere.
Java is strictly object orinted programming language and we
can access any method by using the object.but this is first
method rite now we don't have any object so that static
keyword is used.We can use static method without having the
instance of this class.
void means this function doesn't return anything.
String args[] specified the string array it is use to take
compile time arguments.It takes only String type argument.
There is one question arise if we don't want to pass the
argument although why we use String args[].Answer is
runtime calls always method with String argument but you
can overload main method....
public class Simple
{
public static void main()
{
System.out.println("My Main");
}
public static void main(String args[])
{
Simple.main();
}
}
when you run this program your runtime calls main method
with string arguments first.and then call main method
without arguments and the output will be "My Main".
| Is This Answer Correct ? | 7 Yes | 3 No |
Post New Answer View All Answers
Is array size fixed in java?
What is a flag value?
What are the different tags provided in jstl?
What are the advantages and disadvantages of object cloning?
What is the main purpose of serialization in java?
Why collection doesn’t extend cloneable and serializable interfaces?
What is a buffer in computer?
Is it possible to specify multiple jndi names when deploying an ejb?
Is ruby built on java?
Is the milky way in a void?
Does it matter in what order catch statements for filenotfoundexception and ioexception are written?
What are structs in java?
Are arrays primitive data types?
What is JFC?
How would you format a date in java? I.e. In the ddmmyyy format?