GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  J2EE  >  Core Java
Go To First  |  Previous Question  |  Next Question 
 Core Java  |  Question 451 of 502    Print  
Every application should have a main() method. Under which class does the main() method comes under?

  
Total Answers and Comments: 6 Last Update: March 31, 2009     Asked by: maharamesh87 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: vawani
 
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


Above answer was rated as good by the following members:
sujithkthomas
November 26, 2007 06:15:23   #1  
shivkant.pawan Member Since: November 2007   Contribution: 5    

RE: Every application should have a main() method. Und...
You should have to put the main() method in public class.
 
Is this answer useful? Yes | No
November 29, 2007 12:01:48   #2  
GSSSGopinath Member Since: November 2007   Contribution: 1    

RE: Every application should have a main() method. Under which class does the main() method comes under?
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.
 
Is this answer useful? Yes | No
June 09, 2008 04:40:43   #3  
kiranmai.kasturi Member Since: June 2008   Contribution: 4    

RE: Every application should have a main() method. Under which class does the main() method comes under?
put main method in any class but that class should have public access specifier if you want to execute that method.
 
Is this answer useful? Yes | No
November 03, 2008 06:46:26   #4  
hari.krishna709 Member Since: October 2008   Contribution: 4    

RE: Every application should have a main() method. Under which class does the main() method comes under?
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

 
Is this answer useful? Yes | No
November 04, 2008 02:12:19   #5  
vawani Member Since: July 2006   Contribution: 3    

RE: Every application should have a main() method. Under which class does the main() method comes under?
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

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
March 30, 2009 23:12:31   #6  
shouvanik1979 Member Since: March 2009   Contribution: 5    

RE: Every application should have a main() method. Under which class does the main() method comes under?
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.
 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape