Can we declare the main method of our class as private?

1 votes
274 views
Anonymous User asked 20-Dec-2017 in Technology by Anonymous User

Can we declare the main method of our class as private?

1 Answer

0 votes
Harsh kumar srivastava answered 20-Dec-2017 by Harsh kumar srivastava

Yes, we can! it will compile, but it will not run. In Java we declare the main method of our class as private, it compiles without errors, but it can not be taken as the entry point of your application. When you compile your application it will compile without any error, but at runtime, it throws an exception the main method is not public. On the basis of the above discussion, we reached the conclusion that's you can declare the main method as private but at runtime, it says the main method is not public.

I hope it's informative for you...