The K&B book poses the following question in the self
test for chapter 1 (quation 20).
Given the following,
1. public class CommandArgsThree {
2. public static void main(
String [] args) {
3. String [][] argCopy = new String[2][2];
4. int x;
5. argCopy[0] = args;
6. x = argCopy[0].length;
7. for (int y = 0; y < x; y++) {
8. System.out.print(" " + argCopy[0][y]);
9. }
10. }
11. }
and the command-line invocation,
java CommandArgsThree 1 2 3
what is the result?
A. 0 0
B. 1 2
C. 0 0 0
D. 1 2 3
E. Compilation fails
F. An exception is thrown at runtime
The correct answer is F, because according to the book you shouldn't be able to assign an array with three elements to an array with two elements.
When compiling and running the exact code, I cannot seem to generate any exceptions, regardles of how many command line arguments I use. The command line arguments are output as I entered them.
So in practice it would seem that D is the correct answer.
Any comments would be helpfull.
[ January 12, 2004: Message edited by: Andr� Roodt ]
[ January 12, 2004: Message edited by: Andr� Roodt ]