About Question enthuware.ocajp.i.v7.2.1119 :
Posted: Tue Jul 31, 2012 8:36 pm
Easy test, question 36.
The answer within the enthuware application is wrong. See code below:
What will the above program print if run using the following command line: java Switcher 1 2 3
The program cannot be compiled, therefore it cannot be run. It doesn't matter how the question is worded, the code simply does not compile and it would be wrong to ask someone learning Java to temporarily suspend this and postulate on what might otherwise happen.
The correct answer is "It will not compile because of //1."
Your system tells me "There is no problem here because Integer.parseInt() returns an int."
Sure, while that statement is indeed correct, the "// 1 {" is not correct and causes a compilation error.
Please correct.
The answer within the enthuware application is wrong. See code below:
Code: Select all
public class Switcher{
public static void main(String[] args){
switch(Integer.parseInt(args[1])) //1{
case 0 :
boolean b = false;
break;
case 1 :
b = true; //2
break;
}
if(b) System.out.println(args[2]);
}
}
The program cannot be compiled, therefore it cannot be run. It doesn't matter how the question is worded, the code simply does not compile and it would be wrong to ask someone learning Java to temporarily suspend this and postulate on what might otherwise happen.
The correct answer is "It will not compile because of //1."
Code: Select all
[brrees@mnlowdk03273 ~]$ javac Switcher.java
Switcher.java:4: error: '{' expected
switch(Integer.parseInt(args[1])) //1{
^
1 error
Sure, while that statement is indeed correct, the "// 1 {" is not correct and causes a compilation error.
Please correct.