Comments

 <  Day Day Up  >  

Regardless of the syntax of the comments used, they are vital to understanding the function of a class. In Java, C#, and C++, there are two kinds of comments.

The Extra Java and C# Comment Style

In Java and C#, there are actually three types of comments. In Java, the third comment type ( /** */ ) relates to a form of documentation that Java provides. We will not cover this type of comment in this book. C# provides similar syntax to create XML documents.


The first comment is the old C-style comment, which uses /* (slash-asterisk) to open the comment and */ (asterisk-slash) to close the comment. This type of comment can span more than one line, and it's important not to forget to use the pair of open and close comment symbols for each comment. If you miss the closing comment ( */ ), some of your code might be tagged as a comment and overlooked by the compiler. Here is an example of this type of comment used with the Cabbie class:

 
 /*   This class defines a cabbie and assigns a cab */ 

The second type of comment is the // (slash-slash), which renders everything after it, to the end of the line, a comment. This type of comment spans only one line, so you don't need to remember to use a close comment symbol, but you do need to remember to confine the comment to just one line and not include any live code after the comment. Here is an example of this type of comment used with the Cabbie class:

 
 // Name of the cabbie 
 <  Day Day Up  >  


Object-Oriented Thought Process
Object-Oriented Thought Process, The (3rd Edition)
ISBN: 0672330164
EAN: 2147483647
Year: 2003
Pages: 164
Authors: Matt Weisfeld

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net