Guys in this post we are going to discuss comments in a java program. comments are usually non-executable statement which is meant for the programmers own convenience. A comment is usually an explanation regarding the statement. The java comments are statements that are not executed by the compiler and interpreter. The comments can be used to provide information or explanation about the variable, method, class or any statement. It can also be used to hide program code for a specific time.
Types of Java Comments:
There are three types of comments in Java. They are:1.single line comment
2.multi line comment
3.documentation comment
Single line comment:
It allows only one line. This comment must begin with //.Example:
class singlecomment
{
public static void main(String agrs[])
{
//This is single line comment
system.out.println("This is example of single line comment");
}
}
Multiline comment:
If the comment exceeds more than one line, multiline comment os used. Multi-line comment begins with /* and ends with */.Example:
class multiline
{
public static void main(String args[])
{
/*This is an Example
of Multiline comment*/
system.out.println("this is multiline comments");
}
}
Documentation comment:
Documentation comment is used to generate document automatically.Documentation comment begins with /** ends with */.Example:
class documentationexample
{
public static void main(String args[])
{
/** This is an example of docu,entation line comments*/
System.out.println("This is an example of documentation comments");
}
}
No comments:
Post a Comment