• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why main(String [] args) method must be public  RSS feed

 
Suresh S Nayar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can declare a class as non-public and packageless, and then run its main() method from the current directory.
Why doesn't the main method run if i dont declare it as public?

My question actually is but for the main method, the non-public class's method would actually not be accessible from other packages. So, from the current directory, since the non-public packageless class in question is accessible, shouldn't its main method also be accessible even if it were to not be public?
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why doesn't the main method run if i dont declare it as public?


I believe the main() method used to work -- when called as the starting main method -- even if it wasn't public. But then someone realized that this was silly. If the developer didn't want the method public (ie. callable from any class), why should it be callable from the user? So, it was changed.

As for the other point, maybe that will also be changed, in the future.

Henry
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!