xMethod();
}
a. a static method
b. an instance method
c. a static or an instance method
#
7. What would be the result of attempting to compile and
run the following code?
public class Test {
static int x;
public static void main(String[] args){
System.out.println(“Value is ” + x);
}
}
a. The output “Value is 0” is printed.
b. An “illegal array declaration syntax” compiler error occurs.
c. A “possible reference before assignment” compiler error occurs.
d. A runtime error occurs, because x is not initialized.
#
8. Analyze the following code:
public class Test {
private int t;
a. The variable t is not initialized and therefore causes errors.
b. The variable t is private and therefore cannot be accessed in the
main method.
c. Since t is an instance variable, it cannot appear in the static
main method.
d. The program compiles and runs fine.
#
9. Suppose s is a string with the value “java”. What will be
assigned to x if you execute the following code?
char x = s.charAt(4);
a. ‘a’
b. ‘v’