473,237 Members | 1,265 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,237 software developers and data experts.

two main methods in a single program?

Hi,

Please tell me whether we can have two main methods in a single java program?
Sep 4 '07 #1
6 9970
JosAH
11,448 Expert 8TB
Hi,

Please tell me whether we can have two main methods in a single java program?
Expand|Select|Wrap|Line Numbers
  1. public class Main {
  2.    private double main= 54.42;
  3.    public Main() { }
  4.    public static void main(String[] args) {
  5.       Main main= new Main();
  6.       main.main();
  7.       main.main(42);
  8.       main("can");
  9.    }
  10.    private void main() { System.out.print("yes "); }
  11.    private void main(int i) { System.out.print("you "); }
  12.    private static void main(String s) { System.out.println(s); }
  13. }
  14.  
kind regards,

Jos
Sep 4 '07 #2
Ganon11
3,652 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. public class Main {
  2.    private double main= 54.42;
  3.    public Main() { }
  4.    public static void main(String[] args) {
  5.       Main main= new Main();
  6.       main.main();
  7.       main.main(42);
  8.       main("can");
  9.    }
  10.    private void main() { System.out.print("yes "); }
  11.    private void main(int i) { System.out.print("you "); }
  12.    private static void main(String s) { System.out.println(s); }
  13. }
  14.  
kind regards,

Jos
Blech. That just looks awful.
Sep 4 '07 #3
kreagan
153 100+
Expand|Select|Wrap|Line Numbers
  1. public class Main {
  2.    private double main= 54.42;
  3.    public Main() { }
  4.    public static void main(String[] args) {
  5.       Main main= new Main();
  6.       main.main();
  7.       main.main(42);
  8.       main("can");
  9.    }
  10.    private void main() { System.out.print("yes "); }
  11.    private void main(int i) { System.out.print("you "); }
  12.    private static void main(String s) { System.out.println(s); }
  13. }
  14.  
kind regards,

Jos
1.) Why would you want 2 main functions? Are you trying to implement multithreading or something?

2.) Would you even consider that a main function: private static void main(String s) { System.out.println(s); } ? You are just overloading the main function, nothing more. The difference between a real main function and that overloaded imposter is: the program points and knows to point at the real main function. ... Am I making sense?

3.) That was really cute though.

To answer the poster's question. If you mean a method where the program starts, how can a program start at 2 different places? My answer would be no.
Sep 4 '07 #4
JosAH
11,448 Expert 8TB
1.) Why would you want 2 main functions? Are you trying to implement multithreading or something?
Huh? overloaded methods have nothing to do with multiple thread.

2.) Would you even consider that a main function: private static void main(String s) { System.out.println(s); } ? You are just overloading the main function, nothing more. The difference between a real main function and that overloaded imposter is: the program points and knows to point at the real main function. ... Am I making sense?
Nope, but the OP wasn't making sense either ;-)

3.) That was really cute though.
I know ;-)

To answer the poster's question. If you mean a method where the program starts, how can a program start at 2 different places? My answer would be no.
Yup, and my terrible example just shows that. The question didn't make sense.
Of course different classes can all have a static void main(String[] args) method.

kind regards,

Jos
Sep 4 '07 #5
JosAH
11,448 Expert 8TB
Blech. That just looks awful.
That Sir, is in the eye of the beholder ;-)

kind regards,

Jos
Sep 4 '07 #6
kreagan
153 100+
Huh? overloaded methods have nothing to do with multiple thread.
Sorry, I was refering to the first poster's question, not your crazy program. To me, it sounds like he wants to run 2 programs (threads) with 1 code.

Yup, and my terrible example just shows that. The question didn't make sense.
Of course different classes can all have a static void main(String[] args) method.
Right, but you can only run 1 at a time.
Sep 4 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

99
by: David MacQuigg | last post by:
I'm not getting any feedback on the most important benefit in my proposed "Ideas for Python 3" thread - the unification of methods and functions. Perhaps it was buried among too many other less...
4
by: Rhamphoryncus | last post by:
First a bit about myself. I've been programming in python several years now, and I've got several more years before that with C. I've got a lot of interest in the more theoretical stuff (language...
45
by: Steven T. Hatton | last post by:
This is a purely *hypothetical* question. That means, it's /pretend/, CP. ;-) If you were forced at gunpoint to put all your code in classes, rather than in namespace scope (obviously classes...
7
by: Mark Kamoski | last post by:
Hi Everyone-- Please help. What are the implications, (in terms of memory, application footprint, resource use, threading, and so forth), of using Shared methods? These Shared classes raise...
29
by: John Rivers | last post by:
Hello, What good reason there is for not allowing methods in ASPX pages I can't imagine, but here is how to get around that limitation: (START) <body MS_POSITIONING="FlowLayout"> <form...
13
by: robinsonreyna | last post by:
Hi everyone Is it possible to write a program which do not have a main() function. The program should compile and run. Please give sample code to do this.
12
by: Andrew Poulos | last post by:
With the following code I can't understand why this.num keeps incrementing each time I create a new instance of Foo. For each instance I'm expecting this.num to alert as 1 but keeps incrementing. ...
7
by: Boki | last post by:
Hi All, When we delacre a main, why we dlacre it inside form? Why not outside of form? If form contains main(), why not every form contains a main()... Best regards, Boki.
4
by: chandu | last post by:
Hello, I had one doubt,please clarify it. Main is the entry point for the application. if i had multiple overloaded main methods in my application. how the compiler recognizes the original...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.