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 to print an arraylist in java?
How do I remove a character from a string in java?
Class c implements interface I containing method m1 and m2 declarations. Class c has provided implementation for method m2. Can I create an object of class c?
Implementations of set interface?
What is pass by value?
How we create object in copy constructor?
Does java have extension methods?
What is the final blank variable?
How does finally block differ from finalize() method?
What is use of functional interface in java 8? Explain
How do you compare two strings lexicographically?
What happens if we don’t override run method ?
Is stringwriter thread safe?
How can an object be unreferenced?
Explain about fail fast iterators in java?