in john hunt's mock exam Q.7 what will be the result of compiling the following code: public class Test { public static void main (String args []) { int age; age = age + 1; System.out.println("The age is " + age); } } A.Compiles and runs with no output B.Compiles and runs printing out The age is 1 C.Compiles but generates a runtime error D.Does not compile E.Compiles but generates a compile time error the answer is D i'm wondering why not E, coz i tested it and it did compile but generate an error saying "variable age might not have been initialized". what's the difference between "does not compile" and "compile time error"? thanks
Valentin Crettaz
Gold Digger
Sheriff
Joined: Aug 26, 2001
Posts: 7610
posted
0
if you get a compile-time error it means that it didn't compile. it did compile but generate an error saying "variable age might not have been initialized". then it didn't compile since an error stopped the compiling process. A program DID compile when there are no errors showing up during the compilation process. HIH
------------------ Valentin Crettaz Sun Certified Programmer for Java 2 Platform
Hi Patrick I also got the message that the variable age may not have been initialized. There was no class file generated though and I interprete that as meaning it did not compile. I can't think of an instance when I have ever had a compile time error and yet had the code compile. I assume that the two are mutually exclusive and that the question is checking our knowledge of that. hth Simon
patrick tang
Ranch Hand
Joined: Dec 16, 2001
Posts: 44
posted
0
thanks val and simon, now i know it's a tricky one in wording. it's impossible to compile while generating a compile error...
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: "does not compile" vs "compile time error"