• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

"does not compile" vs "compile time error"

 
patrick tang
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Simon Whitehouse
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks val and simon, now i know
it's a tricky one in wording.
it's impossible to compile while
generating a compile error...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic