What is the need to declare main() method as static in Java?

Answer Posted / bsridhar1984

main() is the entry point of the java program for JVM. If it
is not static and have to call main method, JVM has to
create the object for that class. At this situation
constructor of that class will be entry point.

So that main() method of that class should be static. Then
only JVM can access the main method directly without
creating object of the program.

Is This Answer Correct ?    7 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is eclipse a jdk?

676


Which is better openjdk or oracle jdk?

650


What are the new features about Java se 8 ?

700


What is entitymanager in jpa?

657


What is data persistence in java?

809


What is lambda value?

683


What is the use of flatmap in java 8?

648


Does ms edge support java?

641


How can I swap two variables without using a third variable?

735


What is a controller in java?

663


What is the difference between collection and stream?

698


What are orm tools in java?

790


In a barber shop there are 2 doors. customer come in 1 door, leave in other. minimum # of chairs. barber spend his life in cutting. always barber can cut 1 customer. few chairs in the shop. if barber busy customer waits, if chairs full, customer leave. if no customer, barber sleeps. treat barber and customer as 2 threads. you can use Semaphore class with arrive and depart and count as parameter.

1916


If you’re overriding the method equals() of an object, which other method you might also consider?

734


What is the meaning of loosely coupled in java?

680