File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes nested comments Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "nested comments" Watch "nested comments" New topic
Author

nested comments

Alex Sbityakov
Ranch Hand

Joined: Jul 23, 2001
Posts: 49
I thought nested comments aren't allowed. this compiles and prints "The End"

Bill Tripper
Greenhorn

Joined: May 30, 2001
Posts: 24
Based on your code, nested comments are not allowed. If they were, your code would not compile. I'm not sure what your really asking.
Your first comment runs from the first "/*" to the first "*/". The second "/*" (followed by jkktj) is ignored, since nested comments are not allowed and it's embedded within a comment. The second comment runs from the third "/*" to the second "*/".
Alex Sbityakov
Ranch Hand

Joined: Jul 23, 2001
Posts: 49
It seems the nesting of /*..*/ style comments are not allowed, precisely for the reason that the starting tag of the second set of comments is ignored by the compiler. However, the nesting of // and /*..*/ style comments are OK.
John McErkland
Greenhorn

Joined: Jul 29, 2001
Posts: 4
Originally posted by Alex Sbityakov:
It seems the nesting of /*..*/ style comments are not allowed, precisely for the reason that the starting tag of the second set of comments is ignored by the compiler. However, the nesting of // and /*..*/ style comments are OK.

In your code the first comment starts with /* and doesn't end until jkktj*/. The whole first comment is
/* comment
if (true) {
temp1 temp = new temp1();
System.out.println("Done");
}
/*jkktj*/
then there is a second comment /*comment*/.
So compiler sees no problem.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: nested comments
 
Similar Threads
comments
Comments - Dan's exam question
Nested comments
javac and classpath doubt
Clean Code: A Handbook of Agile Software Craftsmanship - comments in code