Answered Questions

  • What is the Output of the following Java Program

    public interface I1{Static String x="inside I1";public void someMethod();}class A implements I1{ public static void main(String args[[]){ System.out.println("Calling I1 var ..."+I1.x);}}

    Star Read Best Answer

    Editorial / Best Answer

    abuthahir.d  

    • Member Since Jan-2008 | Apr 14th, 2008


    Compilation error due to 2 reasons.
    1. All variables defined in the Interfaces are implicitly public static final. So need not specify "Static" in interface.

    2. If any of the member functions of a Interface is not Overriden , a compilation error will be thrown

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