cancel
Showing results for 
Search instead for 
Did you mean: 

command line argument

Former Member
0 Kudos

hello ! i m a beginner in java. Kindly help me to solve this question.

wat'll happen when u attempt to compile and run this code with the COMMAND LINE "hello there"

public class Arg{

String[] MyArg;

public static void main(String argv[]){

MyArg=argv;

}

public void amethod(){

System.out.println(argv[1]);

}

}

Options--

1.Compile time error

2.Compilation and output of "hello"

3.Compilation and output of "there"

4.none of the above

Accepted Solutions (0)

Answers (1)

Answers (1)

suresh_krishnamoorthy
Active Contributor
0 Kudos

Hi Payal,

Above code will give following error:

java.lang.Error: Unresolved compilation problem:

Cannot make a static reference to the non-static field MyArg

If you run following code you will get following output.

public class Arg{

public static void main(String argv[]){

for (int i=0; i < argv.length; i++)

{

System.out.println(argv[1]);

}

}

}

Output will be:

there

there

Regards, Suresh KB