If we declare the main method as private instead of public it will execute or not
Printable View
If we declare the main method as private instead of public it will execute or not
No error on complile time. But you got the run time error like "main method is not public".
--------------------
suresh
No...because,execution will start from main itself....it needs to accessable by anywhere....
hi ramesh,
Are you trying for this one? Don't you get error at run time?
-------------------
suresh
No U cant declare main method as Private.
During runtime it gives no such method error.
hi ,
In run time,jvm checks main method with this convention(public static void main(String args[]) )
if you dont define this method as actually defined, JVM shows run time error as no such method.it wont execute any statement of any other main method.
[QUOTE=rajesh.tripathi;15112]If we declare the main method as private instead of public it will execute or not[/QUOTE]
NO it will not execute, normally main method is executed by JRE Interpretor
Making it private would not provide access to JRE.
vj
Dear Rajesh,
The Main Method will not execute if you will declare as private . It should be public .
Regards,
Jayant
[QUOTE=rajesh.tripathi;15112]If we declare the main method as private instead of public it will execute or not[/QUOTE]
One can declare the [B]main[/B] method as private, but a main method with private access specifier will not be treated by the java runtime, as entry point of the program.