What will be the output of the following Java snippet, if compiled and executed with command line “hello there”?

public class abc
{
    String[] xyz;
 
    public static void main(String argv[])
    {
        xyz=argv;
    }
 
    public void runMethod()
    {
        System.out.println(argv[1]);
    }
}

a) Compile time error
b) Output would be “hello”
c) Output would be “there”
d) Output would be “hello there”

1 thought on “What will be the output of the following Java snippet, if compiled and executed with command line “hello there”?”

  1. a
    Explanation: Error would be “Cannot make static reference to a non static variable”. Even if main method was not static, the array argv is local to the main method and would not be visible within runMethod.

Leave a Comment