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
How do you convert int to char in java?
What is percentage in java?
What about method local inner classes or local inner classes in java?
What is super keyword explain with example?
What is executor memory?
Is vector thread safe in java?
Compare java and python.
What is a parameter used for?
What is a conditional statement explain with example?
What does compareto () do in java?
What is an escape character in java?
What is import java util arraylist?
Explain the public class modifier?
What are use cases?
How to sort an unsorted array in java?