Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

What happens if I declare main method as private in Java?

user-image
Question ajoutée par Karimuddin Syed , Software Developer , SCHIMATIC TECHNOLOGIES PVT LTD
Date de publication: 2013/06/20
Javed Khan
par Javed Khan , Senior Programmer Analyst , Barclays Technology

Your main will become like any other private method.
Since it is private it cannot be invoked and hence the application cannot be called.

Zabeer Sultan
par Zabeer Sultan , Senior Technical Lead , Happiestminds

Only the main method which is public can be invoked by the JVM.
So a private main method will be treated as any other method which eventually needs to be invoked from a public main method.

Mohammed Ameen
par Mohammed Ameen , Java Developer , TATA Consultancy Services Limited (TCSL)

The Program compiles properly but at the runtime it will give "Main method not public" message.

it will compile fine but at run time it will give you an error "no such method found".

More Questions Like This

Avez-vous besoin d'aide pour créer un CV ayant les mots-clés recherchés par les employeurs?