File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SCJP Brainteaser (12)

 
Shaan Shar
Ranch Hand
Posts: 1249
Java Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What this code will do..

Will it compile or not.



Enjoy Brainteaser.

Will come with some more
 
Joe Harry
Ranch Hand
Posts: 10045
3
Eclipse IDE Mac PPC Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sharma Ji,

The above code won't compile as you are using a label http: not for a loop but for a statement.

Thanks.
 
Asha Lilliete
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The given code is getting compiled
The thing is the label cannot be used.
 
Saurabh Vyas
Ranch Hand
Posts: 72
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the code should compile as it is a valid label and label can be used anywhere.

Good question. a real googly
[ November 14, 2006: Message edited by: Saurabh Vyas ]
 
rajanikar reddy
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think code will compile
 
Shaan Shar
Ranch Hand
Posts: 1249
Java Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by rajanikar reddy:
I think code will compile


Really !!!

Could you also pour your thoughts behind this reason.
 
Rajesh Kadle
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Code will compile.

http : is treaded as label

www.google.com; is commented out in //www.google.com;
 
Shaan Shar
Ranch Hand
Posts: 1249
Java Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rajesh Kadle:
Code will compile.

http : is treaded as label

www.google.com; is commented out in //www.google.com;


Then this means this code will also compile




What are your thoughts now.

Now you can use your PC to check what are the things which are really going on.
 
Saurabh Vyas
Ranch Hand
Posts: 72
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This code will not compile as there is no valid java statement after the label.
There should be atleast one valid java statement after the label which has semi-colon at the end.
 
Harshad Khasnis
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

[/CODE]

No Sharma Ji that certainly not going to compile, but yes this one sure will compile,


[ November 15, 2006: Message edited by: Harshad Khasnis ]
 
Shaan Shar
Ranch Hand
Posts: 1249
Java Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Saurabh Vyas:

This code will not compile as there is no valid java statement after the label.
There should be atleast one valid java statement after the label which has semi-colon at the end.


here we end up by this thread. Very good Catch Saurabh .

That was the only point in this question.

Now Enjoy other BrainTeasers.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic