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)
<B>~James Baud</B><P>He who asks, is a fool for five minutes;<BR>but, he who does not ask, remains a fool forever. (Chinese proverb)
Jane Griscti
Ranch Hand
Joined: Aug 30, 2000
Posts: 3141
posted
0
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
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)