+ 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.
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.
+ 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....(?)
+ 17
There's a point I got :
What's the answer if we change http: to any other name like dhhj: ? Would it work?
+ 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)
+ 16
and what if we don't put a : after http?
+ 16
So, now we're gonna report it to them? 😂
Add label: to the Java course...
+ 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)
+ 11
An interesting note: these types of questions tend to pop up in interview settings. Hence why I took the time posting them
+ 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
+ 10
Wow no one has gotten this completely right so far. And only one person has even guessed the output 😢 (wrong but still guess)
+ 9
The closest to the right answer so far is Sachin, but it is not quite a goto statement mate. 😉
+ 9
That's exactly what I'm saying 😎
+ 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
+ 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.
+ 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
+ 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? 😎
+ 8
@Sachin I specifically was looking for both terms: label and comment 😉
+ 8
You can try, but every language needs to discuss it @Dayve 😎
+ 8
@TheRedSpy I explain it fully up above, but your guess is correct
+ 8
Hot today
I have made a calculator in which my % (Percentage) not work correctly for 100%50 or 100%20.
3 Votes
Python palindrome challenge.
1 Votes
Java
0 Votes
Number of Ones ( C++ ) question!
1 Votes