Answered Questions

  • if there are more than one main method in a program, then which main method will be called.

    what will be the output class A { public static void main(String args[]) { System.out.println("Hi friend"); } } class Test { public static void main(String args[]) { System.out.println(" How are you"); } }

    Manas Naik

    • Jul 7th, 2012

    When we compile it create two different class with name a.class and test.class .so,according to your call it will execute.
    Example--java test
    then output is "how are you" only not hi friend

    Rashmi Ahuja

    • Jun 16th, 2012

    When we execute this class with class B then it first call to class A method main which is like normal method. after that B class print msg is printed

  • Can we override the main method?

    Star Read Best Answer

    Editorial / Best Answer

    ashish_setia  

    • Member Since Oct-2006 | Oct 3rd, 2006


    check out this example

    class Checkmain{
    public static void main(String args[]){
    args[1]="ashish";
    System.out.println("hello ");
    }
    }
    class Checkmain1 extends Checkmain{
    public static void main(String args[]){
    System.out.println("how r u");
    }

    }
    class Jo{
    public static void main(String args[]){
    String S[]=new String[10] ;

    Checkmain.main(S);
    Checkmain1.main(S);
    }}

    vivek

    • Aug 26th, 2017

    Yes you can only do that by overriding main method signature for eg main(String[] args) to main(). Certainly there are no other ways to do that because JVM needs strings array arguments to take comma...

    Dharmendra Singh

    • Sep 15th, 2016

    yes we can"java public class HelloWorld { // arguments are passed using the text field below this editor public static void main(String[] args) { String []s =new Str...