Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Marcus Mock 1 Question 33

 
James Baud
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What will happen when you attempt to compile and run the following code?.
1) It will compile and the run method will print out the increasing value of i.
2) It will compile and calling start will print out the increasing value of i.
3) The code will cause an error at compile time.
4) Compilation will cause an error because while cannot take a parameter of true.

Answer:
3) The code will cause an error at compile time
The error is caused because run should have a void not an int return type.
My Comment: This code may compile if the return type is changed to void and the statement, return 1 removed, but I don't think it will run because there is no main method. My doubt is, is the main method and public class implied in this context?
------------------
~James Baud
He who asks, is a fool for five minutes;
but, he who does not ask, remains a fool forever. (Chinese proverb)
 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi James,
Yes
You have to assume that everything else needed to run the code example exists and is correct. Only analyze the snippet, as it's presented, to determine wether or not it will fail.
Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
 
James Baud
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jane.
------------------
~James Baud
He who asks, is a fool for five minutes;
but, he who does not ask, remains a fool forever. (Chinese proverb)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic