Friday, 31 July 2009

Java Certification Question 0050

Given the following code

public class Sytch{

int x=2000;

public static void main(String argv[]){

System.out.println("Ms "+argv[1]+"Please pay $"+x);

}

}

What will happen if you attempt to compile and run this code with the command line

java Sytch Jones Diggle

1) Compilation and output of Ms Diggle Please pay $2000
2) Compile time error
3) Compilation and output of Ms Jones Please pay $2000
4) Compilation but runtime error


Answer 2:

2) Compile time error

The main method is static and cannot access the non static variable x

No comments:

Post a Comment