Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Does not compile vs Compiles with Error? (John Hunt Mock Exam)

 
Ajay Nair
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys, please help me out with this. The following code is from John Hunt's mock exam:Question 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);
}
}
1.Compiles and runs with no output
2.Compiles and runs printing out The age is 1
3.Compiles but generates a runtime error
4.Does not compile
5.Compiles but generates a compile time error
The answer is 4.
My question is why not 5. How do you differentiate between answers 4 and 5? What is the difference?

 
Rahul Agarwal
Ranch Hand
Posts: 52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
well i agree with u
According to me,there is no difference between
4)Does not compile
5)Compiles but generates a compile time error
 
angel custodio
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I faced this question two days ago. IMO, answer 4 is correct, but is a kind of subtle different against answer 5:
A java source code file is "compiled" when there is no compile time error and thus, a output file .class is produced.
Therefore, if a "compile time error" is produced, no .class file is generated; so we can say "doesn't compile".

Please, correct me if i'm wrong.
Regds.
 
Ajay Nair
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Angelo,
I am sorry I still do not get the difference.
Your statement reads this:
A java source code file is "compiled" when there is no compile time error and thus, a output file .class is produced.
Therefore, if a "compile time error" is produced, no .class file is generated; so we can say "doesn't compile".
This is precisely the doubt. If "doesn't compile" means compile time error and "compiled" means no compile time error, then what does the option 5 mean?
Hell, I am so confused!!
Guys, HELP!!!
 
Jane Griscti
Ranch Hand
Posts: 3141
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ... maybe 5 is referring to code that compiles ie a 'class' file is created but you get warning messages. Similar to the 'deprecated' statements.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic