Every application should have a main() method. Under which class does the main() method comes under?

Questions by maharamesh87

Showing Answers 1 - 14 of 14 Answers

GSSSGopinath

  • Nov 29th, 2007
 

It may not required to put the main method in the public class. But we have to save the file with the public class name. So, it is preferrable to put the main() method in the public class. Other wise we need to remember in which class you put the main method and need to give that class name while running.

Even if you dont have main method we can develop program like
    public class{
 static
  {
   System.out.println("Hello world");
  System.exit(0);
  }
}
this will execute without errors

  Was this answer useful?  Yes

vawani

  • Nov 4th, 2008
 

If you  are writing a program in java then you have to put main method in a class, so  that class is the owner of main method but since  we r declaring it as public it is available to all class ,and also you have to use the modifier STATIC so the JVM can access the method without creating the class object of that class.




regards
MR vawani

main() method should be present in the java class which we execute at the command prompt. for example. c:/> java abc where abc is the class which must have a main() method, because JVM calls the main method of this class after it loads all the classes into its memory.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions