on 09-27-2006 1:19 PM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.