+ 18

Challenge Question (from my declined quizzes) - Guess the output. Don't use playground!

No cheating here. Make an honest attempt at guessing this. What is the output of the following code: public class Curiosity { public static void main(String[] args) { System.out.print("A curiosity "); http: //www.google.com System.out.print("compiler OK"); } } a. Exception b. Error c. compiler OK d. A curiosity compiler OK First to get the correct answer AND correctly explain why the answer is correct wins.

23rd May 2017, 6:51 PM
Ace
Ace - avatar
51 Answers
+ 15
This would be made clear with a basic intro to computer science or engineering course but I digress... http: is a label, used for goto statements​ and branches. Labels​, like comments, are ignored by the compiler. //www.google.com is a comment. Pretty self explanatory there. Thus the answer is d.
24th May 2017, 4:08 AM
Ace
Ace - avatar
+ 17
Output : A curiosity compiler OK (?) Reason : because of // in http://, www.google.com works as a comment in the entire program. Allowing both the outputs to be printed....(?)
24th May 2017, 3:32 AM
Dev
Dev - avatar
+ 17
There's a point I got : What's the answer if we change http: to any other name like dhhj: ? Would it work?
24th May 2017, 4:03 AM
Dev
Dev - avatar
+ 16
I'm going for d too because the "jumping goto statement thing" is there but never "called" so I reckon it can be ignored in this case. (I know the //www.google.com bit is definitely ignored because it's a comment)
24th May 2017, 1:21 AM
Jafca
Jafca - avatar
+ 16
and what if we don't put a : after http?
24th May 2017, 4:05 AM
Dev
Dev - avatar
+ 16
So, now we're gonna report it to them? 😂 Add label: to the Java course...
24th May 2017, 4:15 AM
Dev
Dev - avatar
+ 14
Adding onto what @Sachin and @Steven have said, the (word): is like a goto statement except that you don't go to it, you go to the line after it (if that makes sense)
23rd May 2017, 10:59 PM
Jafca
Jafca - avatar
+ 11
An interesting note: these types of questions tend to pop up in interview settings. Hence why I took the time posting them
24th May 2017, 4:22 AM
Ace
Ace - avatar
+ 10
http: in here looks like goto statement we use in C, if there exists a goto statement in java also, then the code will run perfectly, else syntax error (Which I thought at first sight). But in java, break is used in place of goto. Check- http://www.aboutcodes.com/2012/07/goto-statement-in-java-with-example.html?m=1
23rd May 2017, 7:48 PM
Sachin Artani
Sachin Artani - avatar
+ 10
Wow no one has gotten this completely right so far. And only one person has even guessed the output 😢 (wrong but still guess)
24th May 2017, 12:42 AM
Ace
Ace - avatar
+ 9
The closest to the right answer so far is Sachin, but it is not quite a goto statement mate. 😉
23rd May 2017, 10:31 PM
Ace
Ace - avatar
+ 9
That's exactly what I'm ​saying 😎
23rd May 2017, 10:55 PM
Ace
Ace - avatar
+ 9
the answer is the option d because the http //www.Google.com is treated as comment and it is not executed and system prints the output as option d
24th May 2017, 2:05 AM
MsJ
MsJ - avatar
+ 9
I thought this would not be that difficult honestly, but I guess it shows how these courses skip over key ideas needed for a true computer science education.
24th May 2017, 4:10 AM
Ace
Ace - avatar
+ 9
I posted a lot of these types of questions that actually get into real CS not just assess the math ability. All but one got declined thus far and I am not reposting them
24th May 2017, 4:18 AM
Ace
Ace - avatar
+ 8
Okay we're getting somewhere... the answer is d, and there is a comment in the line which many of you have said is //www.google.com 👍 But this is NOT a comment: http: //what is this? 😎
24th May 2017, 3:38 AM
Ace
Ace - avatar
+ 8
@Sachin I specifically was looking for both terms: label and comment 😉
24th May 2017, 4:12 AM
Ace
Ace - avatar
+ 8
You can try, but every language needs to discuss it @Dayve 😎
24th May 2017, 4:16 AM
Ace
Ace - avatar
+ 8
@TheRedSpy I explain it fully up above, but your guess is correct
24th May 2017, 4:20 AM
Ace
Ace - avatar
24th May 2017, 4:33 AM
Ace
Ace - avatar