Tuesday, 8 September 2009

Java Certification Question 0089

What will happen when you attempt to compile and run the following 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]);
}
}

1) Compile time error
2) Compilation and output of "hello"
3) Compilation and output of "there"
4) None of the above





Answer)

1) Compile time error

You will get an error saying something like "Cant make a static reference to a non static variable". Note that the main method is static.

No comments: