Hi Ranchers
A question often comes to my mind - "Why is main() method public?"
We may say that main() must be accessible to JVM as JVM calls main() directly at runtime that is why it should be public.
Lets have a look at following code -
class X
{
public static void main(
String[] s)
{
}
}
Here the class is not public but main() is public. And the code works fine.
My question is -
If the class is not public (thus may not be accessible directly by JVM) then what is the point in declaring main() as public.
(If class is not accessible its method also wont be accessible).
Please explain and correct me where I m wrong.