Why do we need main method to execute a java program?

Answer Posted / javamasque

Main method is auto called by JVM. It is the place, where JVM enters into the class. It is called before the class is instantiated by its constructor. There are below reasons on its signature.
1. Public access modifier: it is visible to outer environment called JVM.
2. Static non-access modifier: it is called before the class is instantiated, hence JVM use class name to call the main method.
3. Void return type: It return no value to JVM.
4. String array parameter: It takes command line arguments.

Is This Answer Correct ?    11 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Which class cannot be a subclass in java?

718


How to change the priority of thread or how to set the priority of thread?

825


What is the difference between yielding and sleeping?

786


What is increment in java?

725


Why can't you declare a class as protected?

795


Write a program in java to create a doubly linked list containing n nodes.

740


What interface is extended by awt event listeners?

813


What is a ternary operator in java?

755


What is the use of conditional statement?

738


Difference between Linked list and Queue?

796


When is the finalize() called? What is the purpose of finalization?

824


what are different ways in which a thread can enter the waiting state? : Java thread

705


Is arraylist ordered?

770


Can a final method be overloaded?

715


What is the use of predicate in java 8?

685