Two Laptop Bag
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes main Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "main" Watch "main" New topic


hemamalini s.

Joined: Oct 17, 2005
Posts: 13
Why main() method must be public so that it be called from JVM?
why class name may not be public in which main method is there cause ?JVM is outside the class>...........
Patrick Punty

Joined: Jul 01, 2005
Posts: 24
Well for your first querry I feel the answer is Yes, so that JVM can call it.
and I am sorry I didnt get your second querry
Raghu Shree
Ranch Hand

Joined: Mar 18, 2005
Posts: 143
Public methods are only accessible from outside of the class. main() method is the entry point of the java applications. so we should declare the main method as public.

Raghu J<br />SCJP 1.4<br /> <br />The Wind and waters are always<br />on the side of the ablest navigators.<br /><a href="" target="_blank" rel="nofollow">SCJP Group</a><br /><a href="" target="_blank" rel="nofollow">SCWCD Group</a>
marc weber

Joined: Aug 31, 2004
Posts: 11343

main was not required to be public until Java 1.4.

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
hemamalini s.

Joined: Oct 17, 2005
Posts: 13
jvm is outside the class . it can call public main() is right.but what if class is in default access and public main is there.then also it is able to call it.
I just want to ask how JVM enters a non-public class?
I agree. Here's the link:
subject: main
jQuery in Action, 3rd edition