• Post Reply Bookmark Topic Watch Topic
  • New Topic

Please share your views on the output of this code  RSS feed

 
Abhijeet Ravankar
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This code does not throw NullPointerException. It does throw when i is not static. obj.method() returns null and null.i does not throw exception.
It has something to do with static. Please comment.

I typed in the URL and still the code below compliles. Please comment. Why is it allowed?
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Static members do not require an instance, and the URL is a happy coincidence of valid syntax, because http: is regarded as a label and everything after // as a comment.
 
Abhijeet Ravankar
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok got it. Never used goto .... so forgot labels. Thanks !
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Labels aren't used for goto's -- goto is inherently evil and should be avoided unless there really is no other choice (like VB's error handling...).
In Java, labels are only used in labeled breaks and labeled continues, which allow you to break out of a loop that is containing the current loop.
 
Abhijeet Ravankar
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for further clarification. Never used goto till now. And hardly remember when I used labeled breaks;
Thanks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!