DEV Community

Discussion on: Can the class containing `main` be private?

Collapse
 
cyberhck profile image
Nishchal Gautam

Yes, you can make it private, but your JRE (runtime) calls YourJar.main() which isn't available and will fail (its like what happens when you try to invoke a private method) I think it should have exact same error message (because main is called on runtime, compiler doesn't complain, because no one is calling that method, yet)

Collapse
 
baenencalin profile image
Calin Baenen

Ol, wb the class containing main inside it?

Collapse
 
cyberhck profile image
Nishchal Gautam

I'm not sure if I follow,
basically your java vm will simply call your class.main method, and when it finds that it's private or doesn't even exist, then it'll throw up

Thread Thread
 
baenencalin profile image
Calin Baenen

Ok. Thanks.