• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

"does not compile" vs "compile time error"

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic