This week's book giveaway is in the OCP forum.
We're giving away four copies of OCP Java SE 8 Programmer II Exam Study Guide and have Kathy Sierra, Bert Bates, & Elizabeth Robson on-line!
See this thread for details.
Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

main() doubts  RSS feed

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can anyone tell me to which to class main() belongs,as we know for each method there is a particular class.so main() as a method it should be under a class that would be predefined.

Thanks
 
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It belongs to the class you want to execute. It can be any class.
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is predefinied by the JVM.
 
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Mahesh Barik:
...so main() as a method it should be under a class that would be predefined...


A "main" method is not predefined for any particular class. It can be included in any class you decide to put it in. What is predefined is the way main (with the proper signature) is used as an entry point...

"A Java virtual machine starts execution by invoking the method main of some specified class..." (JLS - 12.1 Virtual Machine Start Up).
[ October 10, 2006: Message edited by: marc weber ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!