File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes difference btwn Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "difference btwn "does not compile" and "complie time error"" Watch "difference btwn "does not compile" and "complie time error"" New topic

difference btwn "does not compile" and "complie time error"

lucy hu
Ranch Hand

Joined: Aug 21, 2000
Posts: 60
hi, guys, this is a problem from Mock test of JonnHunt
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
could anybody tell me why the answer is D, not E?
Michael Ernest
High Plains Drifter

Joined: Oct 25, 2000
Posts: 7292

Hi Lucy -
I'm guessing that E is a misleading answer, i.e., there's no such situation, so E can never be true.
Possibly the author means to say "The code compiles but generates a compile-time warning." I see this situation when I use deprecated methods -- there may be other situations that do this too, but that's a guess.
Michael Ernest, co-author of:

    The Complete Java 2 Certification Study Guide

    [This message has been edited by Michael Ernest (edited December 03, 2000).]

Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
rahul attaluri

Joined: Nov 22, 2000
Posts: 3
u r using a local variable, when u try to compile, it says variable i may not have been initialized.u have to initialize local variables explicitly.initialize age to 0 and it'll work.
whereas for class variables they r automatically intialized once declared(eg:int variable to 0,boolean to false etc).
arrays too r intialized once declared.
Sahir Shah
Ranch Hand

Joined: Nov 05, 2000
Posts: 158
Maybe by "generating a compile time error" he means he means
"this will drive the compiler nutz ".
And it is possible. Try this out and see what happens.
public class Outer{
public static class Inner{
public static int a = 1;
public static void main(String[] args)
System.out.println(new Outer().Inner.a);
[This message has been edited by Sahir Shah (edited December 04, 2000).]

Ajith removed the Java Steaming Coffee Cup logo (the official Java technology logo). Please note that this logo is is reserved for Sun's use ONLY and cannot be reproduced on product packaging, marketing materials. web pages, etc

[This message has been edited by Ajith Kallambella (edited December 05, 2000).]

I agree. Here's the link:
subject: difference btwn "does not compile" and "complie time error"
It's not a secret anymore!