In Java why we write public static void main(String args[])
why not main()?
Answer Posted / angela
when we run java program, jvm internally calls "main" method.
jvm is built in such a way that it searches for the entire
signature of "main" method i.e public static void
main(String a[])
Example program :
----------------------
class Demo
{
public static void main(String a[])
{ }
}
String a[] -> is used to pass values at runtime.
(c:/>java Demo hai)
public -> providing accessibility for outside code (jvm).
static -> without creating an object calling "main" method
with the class name
c:/>javac Demo.java
c:/>java Demo
(here java internally calls jvm and passes class name
Demo, then jvm loads Demo class and calls Demo.main()
without creating object )
void -> does not return any value because jvm simply calls
main() method and does not have a variable to assign return
value.
Is This Answer Correct ? | 23 Yes | 1 No |
Post New Answer View All Answers
What are scriptlets?
Difference between java and javascript
Is array a class?
What is class array in java?
Can You Have Virtual Functions In Java?
Can we access instance variables within static methods ?
Can we have 2 main methods in java class?
What is final variable?
How do you compare objects in java?
What is a method vs function?
Difference between method overloading and overriding.
Explain about main() method in java ?
What is implicit object in java?
Why is it called buffering?
Can we convert stringbuilder to string in java?