What happens when a main method is declared as private?

Answer Posted / sachin

JVM wants to execute the class its starting Execution from main Method means if JVM wants to execute main method if we declare main Method as private then its restriction the scope of main method if we declare Main Method as public then only jvm can applicable to access the main Method.
for e.g
class SE3
{
private static void main(String[] args)
{
System.out.prinln("Hello");
}
}
E:A_coreResearch_Programs>javac SE3.java

E:A_coreResearch_Programs>java SE3
Error: Main method not found in class SE3, please define the main method as
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to compare strings in java?

497


Is java se free?

518


What are the two categories of data types in the java programming language?

500


Explain wrapper classes in java?

524


What type of language is java?

538






Differentiate between class and structure.

622


Is null or empty java?

529


Why do we create threads in java?

570


What is meant by binding in rmi?

541


What is an immutable class? How to create an immutable class?

533


Explain heap sort?

698


Give an example of call be reference significance.

605


How do you start a thread?

542


How many arguments can be passed to main ()?

518


Give differences between Quicksort &Mergesort. When should these sorts be used andwhat is their running time in java?

676