On 2009-06-10, aks_java <> wrote:
> On Jun 10, 8:48*am, Bent C Dalager <b...@pvv.ntnu.no> wrote:
>> On 2009-06-10, aks_java <atind...@gmail.com> wrote:
>>
>> > Now here's my problem: How do I've two main methods in a single java
>> > package ?
>>
>> Put them in separate files. In your example, put Checkmain in
>> Checkmain.java, Checkmain1 in Checkmain1.java and Jo in Jo.java.
>>
>
> Thanks, now it works. Is this the same as overriding the main method ?
No, the main method is static so you can't override it.
When you run the program you need to choose which class gets to run
and it is the main method in this class that will be executed. If you
say you want to run the Checkmain class, then Checkmain's main() will
be run and if you say you want to run the Checkmain1 class, then
Checkmain1's main() will be run.
That Checkmain1 is derived from Checkmain is not significant in this
case since everything happens in a static context.
Cheers,
Bent D
--
Bent Dalager -
-
http://www.pvv.org/~bcd
powered by emacs