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

What is variable in java?

516


Which package is used for pattern matching with regular expressions?

634


What are methods in java?

532


What is the primitive type byte?

569


What is package protected in java?

518






What do you mean by synchronized non access modifier?

558


When should we create our own custom exception classes?

577


What is hashset in java?

522


Can we make constructors static?

714


What is bom encoding?

545


What is isa relationship?

558


What is the use of System class?

602


Does list maintain insertion order java?

529


Which collection is best for sorting in java?

685


Explain about object oriented programming and its features?

585