Answered Questions

  • 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...