Interview Questions  

Go Back   Interview Questions > Interview Questions & Answers > Information Technology > Java > Core Java

Core Java Core Java Interview Questions, Learn by sharing Core Java Interview Questions asked in various companies, Get Career advices, Interview Procedures from Core Java experts, Post asked Core Java Interview Questions and Answers.

   

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-21-2008, 01:47 PM
Junior Member
 
Join Date: Apr 2008
Posts: 12
Default can we have more than one main method in a program

can we have more than one main method in a program
Reply With Quote
  #2 (permalink)  
Old 04-22-2008, 03:29 PM
Junior Member
 
Join Date: Apr 2008
Posts: 1
Default re:

Only one main() should be in one program, bcoz main() provides start to a program. If u r not agreed then please post the detailed reason of disagreement
Reply With Quote
  #3 (permalink)  
Old 04-23-2008, 10:53 AM
Junior Member
 
Join Date: Apr 2008
Posts: 12
Default more then one main() method

Quote:
Originally Posted by rimita_chakraborty View Post
Only one main() should be in one program, bcoz main() provides start to a program. If u r not agreed then please post the detailed reason of disagreement
it seems we can have more then one main method in case matrixes. however I am not familiar with this aspect of it. if you were to get any information please post it
Reply With Quote
  #4 (permalink)  
Old 05-16-2008, 07:25 AM
Junior Member
 
Join Date: May 2008
Posts: 1
Thumbs up More than one main method in java

class twomain
{
public static void main(float[] args) {
System.out.println("float[] args");
}
public static void main(String[] args) {
System.out.println("String[] args");
}

public static void main(int[] args) {
System.out.println("int[] args");
}

}
output:
String[] args
Reply With Quote
  #5 (permalink)  
Old 05-16-2008, 08:56 AM
Junior Member
 
Join Date: May 2008
Posts: 15
Default

we can have as many main() methods AS LONG AS THEY DIFFER IN CASE. OR THEY ARE OVERLOADED.
ie. it is perfectly fine to have methods like Main(), mAin() or MAIN() IN UR PROGRAM BUT there should be ONLY 1 main() method as the jvm searches for this method in the file..

Last edited by vaneeb; 05-16-2008 at 08:59 AM.
Reply With Quote
  #6 (permalink)  
Old 05-19-2008, 12:33 PM
Junior Member
 
Join Date: May 2008
Posts: 1
Default

only one main method is currect for the one program
Reply With Quote
  #7 (permalink)  
Old 05-26-2008, 07:43 AM
Junior Member
 
Join Date: May 2008
Posts: 28
Default

Only one main method is in the Application because if there is more than one main method than the program throw the exception that from where that application should start.
Reply With Quote
  #8 (permalink)  
Old 06-26-2008, 07:30 AM
Junior Member
 
Join Date: Jun 2008
Posts: 6
Default

u have written d class & classname it is not d main method .
Reply With Quote
  #9 (permalink)  
Old 06-26-2008, 06:27 PM
Junior Member
 
Join Date: Jun 2008
Posts: 16
Default can have many main() methods

u can have as many main() methods in a class,but there should b only on main() method with signature public static.coz whn jvm loads the class it searches for static main() method first,and only staic main() methods can b called by jvm as it does not need an object to b created to call it.
Reply With Quote
  #10 (permalink)  
Old 07-05-2008, 06:36 AM
Junior Member
 
Join Date: Jul 2008
Posts: 9
Default

yeswe can decalre more than one main().but parameter list or case latter must be
different.like
class a
{
public static void main(String arg[])
{
System.out.print("hy this is main");
}

public static void MAIN(String arg[])
{
System.out.print("hy this is MAIN");
}
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On