Saturday, October 10, 2009

SCJP exercise : identifiers

Exercise 1 :

Given the following :

public class Test {
public static void main(String [] args) {
int $test = 10;
System.out.println("$test=" + $test);

}

}

What is the result ? (choose Two)

A $test=10
B $test=null
C Compilation fails
D An exception is thrown at runtime


Exercise 2

Given the following :

public class Test {
public static void main(String [] args) {
int $2test = 10;
System.out.println("$2test=" + $2test);

}

}

What is the result ? (choose Two)

A $2test=10
B $test=null
C Compilation fails
D An exception is thrown at runtime














Solution Exercise 1 :

The solution is A. An identifier can begin with $ or _ .

Solution Exercice 2 :

The correct answer is A. An identifier can't begin with a number but can have a number.

No comments:

Post a Comment