wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark ""does not compile"  vs  "compile time error"" Watch ""does not compile"  vs  "compile time error"" New topic
Author

"does not compile" vs "compile time error"

patrick tang
Ranch Hand

Joined: Dec 16, 2001
Posts: 44
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
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


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Simon Whitehouse
Greenhorn

Joined: Dec 10, 2001
Posts: 12
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
thanks val and simon, now i know
it's a tricky one in wording.
it's impossible to compile while
generating a compile error...
 
Consider Paul's rocket mass heater.
 
subject: "does not compile" vs "compile time error"
 
Similar Threads
a question about method local variables
ambiguous statement
difference btwn "does not compile" and "complie time error"
Does not compile vs Compiles with Error? (John Hunt Mock Exam)
Compiles / Compiles but generate error??