Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

main

 
hemamalini s.
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
main was not required to be public until Java 1.4.
 
hemamalini s.
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jvm is outside the class . it can call public main() method.it 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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic