Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Java (http://www.go4expert.com/forums/java/)
-   -   Java Main() (http://www.go4expert.com/forums/java-main-t27291/)

c_user 6Dec2011 10:21

Java Main()
 
Hi frds,
can there be more than one main() method in a single program.
please justify.
thanking you
:thinking:

guptasandeep 10Dec2011 17:18

Re: Java Main()
 
yes there can be more than one main method in a single program but in different class.

miteshaegis 20Nov2012 18:27

Re: Java Main()
 
Hi,

You can use more than one main method in different class.

thanks

ManzZup 23Nov2012 21:14

Re: Java Main()
 
if you are asking about overloads yes

ArnavKumar 8Nov2013 13:34

Re: Java Main()
 
The number of main methods can not be greater than number of classes. Each class can have its own main method. But a class can not have more than one main method.

ManzZup 8Nov2013 21:25

Re: Java Main()
 
a class can, the jvm looks only for the one that matches the correct format
rest it ignores and throw the NoMainMethodFound kinda exception if you try to run it

ArnavKumar 25Nov2013 12:37

Re: Java Main()
 
Code: java

public class FirstMain {

    protected void main(){

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

class SecondMain{
       
    private int main(int a){
        return a;
    }
   
    protected void main(){

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

class ThirdMain{
    protected void main(){

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

Here you are having different mains in different classes. Are you looking for this?


All times are GMT +5.5. The time now is 01:50.