In Java why we write public static void main(String args[])
why not main()?
Answer Posted / madhu
public static void main()
Public:-->The method is public because it be accessible to
the JVM to begin execution of the program JVM is outside of
the class.
Static:--> It is Static because it be available for
execution without an object instance. you may know that you
need an object instance to invoke any method. So you cannot
begin execution of a class without its object if the main
method was not static
Void:--> It returns only a void because, once the main
method execution is over, the program terminates. So there
can be no data that can be returned by the Main method
Main:--> Main() is the entry point of the program. Rather
we can say it is the main gate to enter inside the
apartment. It should be public because the compiler need to
enter inside the method (The guest need to access the
apartment to reach the security guard).
Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What is constructor in java ?
When parseint method can be used?
Why is the singleton pattern considered to be an anti pattern?
What are 3 data types?
Is age discrete or continuous?
Can we create a constructor in abstract class?
Can a static class have a constructor java?
What are the wrapped, classes?
Can we have any other return type than void for main method?
What is a protected void?
What is an object’s lock and which object’s have locks?
Explain the different forms of polymorphism?
how to create multithreaded program? Explain different ways of using thread? When a thread is created and started, what is its initial state? Or extending thread class or implementing runnable interface. Which is better? : Java thread
What is use of static method?
What is a file pointer?