开发者

My java code has an obvious error. Why does it compile and run?

public class HelloWorld {
    public static void main (String args[]){
        System.out.println ("Hello ");
        http://www.google.com
        System.out.println ("World!");
    }
}

The above code is just compiling and executing fine. Why the c开发者_Python百科ompiler is not reporting any error?


The http: is a Label Statement. See here also.

The //www.google.com portion is then interpreted as a // comment.


Because http: it consider it as label and then rest part are under comment

Basic Usage of Label :

label1:
for(){
  label2:
  for(){
      if(condition1)
      break label1;//break outerloop

      if(condition2)
      break label2;//break innerloop
  }
}    
  • Sun Official Document Describing Label
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜